如何将summary()提取到适用于ggplot()中的数据可视化的数据框?

问题描述 投票:0回答:1

我在存在的情况下正在执行competing risks。我使用prodlim-package,发现它非常有用。但是,我不喜欢内置图形,而是想应用ggplot

问题:如何提取prodlim summary()输出并将其加载到可访问的中?

也许可以写来做到这一点?就将help输出加载到summary()而言,我以前在StackOverflow上收到过dataframe,但其包装与prodlim不同。

library(prodlim)
library(riskRegression)

# Build-in data
data(Melanoma)

# Simple competing risk analysis
fit.aj <- prodlim(Hist(time,status)~age+sex,data=Melanoma)

# Defining the event of interest as cause=1
summary(fit.aj,conf.int=FALSE,newdata=data.frame(age=50,sex="Male"),cause=1)

哪个产量

> summary(fit.aj,conf.int=FALSE,newdata=data.frame(age=50,sex="Male"),cause=1)

----------> Cause:  1 

age=50, sex=Male :
  time n.risk n.event n.lost cuminc se.cuminc lower upper
1   10     33       0      0  0.000    0.0000 0.000 0.000
2 1513     22       0      0  0.282    0.0795 0.126 0.437
3 2006     15       0      0  0.282    0.0795 0.126 0.437
4 3042     10       0      0  0.396    0.0998 0.201 0.592
5 5565      0       0      0     NA        NA    NA    NA

摘要可以很容易地绘制;但是,图形不是我的风格。

plot(fit.aj,conf.int=FALSE,newdata=data.frame(age=50,sex="Male"),cause=1)

enter image description here

我想将summary()转换为dataframe(简称为df),可以将其包含在ggplot()中。

基于names中的summary(),我正在尝试实现以下目标:

ggplot(df, aes(x=time)) +
geom_line(aes(y=cuminc) +
geom_ribbon(aes(ymin = lower, ymax = upper)

感谢您的建议。

r dataframe ggplot2 data-manipulation survival-analysis
1个回答
0
投票

您可以访问结果列表,直到找到绘图表的级别,并将其另存为data.frame。您可以使用str检查列表的结构。

summ_list <- summary(fit.aj,conf.int=FALSE,newdata=data.frame(age=50,sex="Male"),cause=1)
df<-as.data.frame(summ_list $table$`1`$`age=50, sex=Male`)

#The desired plot with ggplot
ggplot(df, aes(x=time)) +
  geom_line(aes(y=cuminc)) +
  geom_ribbon(aes(ymin = lower, 
                              ymax = upper))

ggplot

© www.soinside.com 2019 - 2024. All rights reserved.