I have made a cumulative incidence plot using cmprsk::cuminc
and then ggcompetingrisks
for plotting. I want to change legend labels for the group. I've tried with legend.lab = c("A", "B", "C")
. This works when I do a ggsurvplot
without competing risk. But it does not work now. Any suggestions?
My code is like:
fit <- cuminc(df$Time, df$Event, group = df$genotype)
p <- ggcompetingrisks(fit, multiple_panels = FALSE, palette = "black",
legend.title = c("genotype"),
legend.labs = c("A", "B", "C"))
The thing is that the legend show both the Event (0, 1) and the Group (1, 2, 3). I want only the group to be shown in the legend and I want it to be named A, B and C..
Please help me!!
If I get your fit correct, group will be plotted as linetype so you can use scale_linetype_manual()
to set the title of the legend, and the names. To turn of the other legend about event, you can use guides()
See below for an example using some simulated data:
library(survminer)
library(ggplot2)
library(cmprsk)
df = data.frame(
Time = rexp(100),
genotype = factor(sample(1:3,100,replace=TRUE)),
Event = factor(sample(0:1,100,replace=TRUE),0:1,c('no event', 'death'))
)
fit <- cuminc(df$Time, df$Event, group = df$genotype)
ggcompetingrisks(fit)
p <- ggcompetingrisks(fit, multiple_panels = FALSE)
p + scale_linetype_manual(name="genotype",values=1:3,labels=c("A","B","C"))+
guides(col="none")
Please do dput(df) and paste the output as part of your question if the df I have above is different from yours. This way others can help as well.
If you need thicker lines, do:
old_geom <- ggplot2:::check_subclass("line", "Geom")$default_aes
update_geom_defaults("line", list(size = 1.5))
p + scale_linetype_manual(name="genotype",values=1:3,labels=c("A","B","C"))+
guides(col="none")
update_geom_defaults("line", list(size = old_geom$size))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.