用ggjoy绘制来自survfit的df

时间:2018-03-20 14:16:49

标签: r ggplot2 density-plot

我创建了一个survfit对象 km_sex 并将信息提取到数据框 res

library(ggjoy) 

res <- structure(list(time = c(0, 1, 2, 3), n.risk = c(31832, 29073, 
28876, 28755), n.event = c(2759, 197, 121, 132), n.censor = c(0, 
0, 0, 0), surv = c(0.913326212616235, 0.907137471726564, 0.903336265393315, 
0.899189494847952), std.err = c(0.0017266287300287, 0.00179329499017424, 
0.00183347544957481, 0.00187670201456087), upper = c(0.916422263130943, 
0.910331482557659, 0.906588285320655, 0.902503045443145), lower = 
c(0.91024062183082, 
0.90395466747833, 0.900095910776214, 0.895888109992921), strata = 
structure(c(1L, 
1L, 1L, 1L), .Label = c("deceased_sex=1", "deceased_sex=2"), class = 
"factor"), 
deceased_sex = structure(c(1L, 1L, 1L, 1L), .Label = c("1", 
"2"), class = "factor")), .Names = c("time", "n.risk", "n.event", 
"n.censor", "surv", "std.err", "upper", "lower", "strata", "deceased_sex"
), table = structure(list(records = c(31832, 21671), n.max = c(31832, 
21671), n.start = c(31832, 21671), events = c(31832, 21671), 
`*rmean` = c(54.3844558934406, 53.3710027225324), `*se(rmean)` = 
c(0.147877642847203, 
0.199661595406316), median = c(61, 62), `0.95LCL` = c(61, 
62), `0.95UCL` = c(62, 63)), .Names = c("records", "n.max", 
"n.start", "events", "*rmean", "*se(rmean)", "median", "0.95LCL", 
"0.95UCL"), row.names = c("deceased_sex=1", "deceased_sex=2"), class = 
"data.frame"), row.names = c(NA, 
4L), class = "data.frame")

所以,我想在一个关节图中绘制这些信息,以查看不同生存曲线的密度。 目前我正在使用:

ggplot() + 
   geom_line(data = res, aes(x=time, y = surv, group=deceased_sex, fill=deceased_sex)) +
   geom_joy(scale = 4, stat = "density") +
   scale_fill_brewer(palette = 1) +
   theme_joy()

我有这个情节,但给了我 Desired Result Image

  

“忽视未知的美学:填补”。

但我需要一个填充区域,例如:

Desired Result Image

  • R版本3.4.2(2017-09-28)
  • 平台:x86_64-w64-mingw32 / x64(64位)
  • 在以下位置运行:Windows&gt; = 8 x64(build 9200)

0 个答案:

没有答案