1

I have created a survfit object km_sex and extract the information to a data frame 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")

So, I want to plot this information in a joyplot to see de density of diferents survival curves. Currently I'm using:

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()

And I have this plot but gives me: Desired Result Image

"Ignoring unknown aesthetics: fill".

But I need to have a filled area, such as:

Desired Result Image


  • R version 3.4.2 (2017-09-28)
  • Platform: x86_64-w64-mingw32/x64 (64-bit)
  • Running under: Windows >= 8 x64 (build 9200)
Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
xpto
  • 11
  • 3
  • Please provide [reproducible-example data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – zx8754 Mar 20 '18 at 14:21
  • 1
    The "fill" option will not work for geom_line() - it works only for geoms where you are plotting and then filling an area (e.g., geom_density()). – Isabella Ghement Mar 20 '18 at 15:25
  • With `geom_density()` show: Error in eval(substitute(list(...)), _data, parent.frame()) : object 'y' not found – xpto Mar 20 '18 at 15:46
  • With `ggplot(data = res, aes(x=time, y = surv, group=deceased_sex, fill=deceased_sex))` not appear curves – xpto Mar 20 '18 at 15:52
  • @zx8754 any idea?? – xpto Mar 20 '18 at 18:54
  • Why ggjoy? I think you need line plot with area under it coloured with alpha. If you insist on using ggjoy, I don't understand the expected plot, what will be your Yaxis? (btw, ggjoy is now replaced by `ggridges::geom_density_ridges`) – zx8754 Mar 20 '18 at 20:18
  • @zx8754 in my Yaxis i want deceased_sex=1 and deceased_sex=2.So, i want to show the different curves in Yaxis. – xpto Mar 27 '18 at 17:13

0 Answers0