admin管理员组文章数量:1122832
I am using ggsurvfit package to create KM plots. I am having one grouping variable and looking to add legend for that variable.
Please check code below: I am looking to add legend to this particular plot.
library(ggsurvfit)
survfit2(Surv(time, status) ~ 1, data = df_colon) %>%
ggsurvfit(color = "#508050") +
add_confidence_interval(fill = "#508050") +
add_risktable() +
scale_ggsurvfit()
How can we add legend in the above-mentioned km plot?
I am using ggsurvfit package to create KM plots. I am having one grouping variable and looking to add legend for that variable.
Please check code below: I am looking to add legend to this particular plot.
library(ggsurvfit)
survfit2(Surv(time, status) ~ 1, data = df_colon) %>%
ggsurvfit(color = "#508050") +
add_confidence_interval(fill = "#508050") +
add_risktable() +
scale_ggsurvfit()
How can we add legend in the above-mentioned km plot?
Share Improve this question edited Nov 21, 2024 at 17:40 stefan 123k6 gold badges36 silver badges72 bronze badges Recognized by R Language Collective asked Nov 21, 2024 at 17:11 Bharath kumar TAMATAMALABharath kumar TAMATAMALA 111 silver badge1 bronze badge1 Answer
Reset to default 3A simple way would be to add aes()
to the plot, mapping color and fill aesthetics to the string you wish to appear in the legend. Again, include manual scales to specify the actual colors you wish to appear.
survfit2(Surv(time, status) ~ 1, data = df_colon) %>%
ggsurvfit() +
add_confidence_interval() +
add_risktable() +
scale_ggsurvfit() +
aes(color = "Your label here", fill = "Your label here") +
scale_color_manual(NULL, values = "#508050") +
scale_fill_manual(NULL, values = "#508050") +
theme(legend.position = "right")
本文标签: rHow to add legend when we have one grouping variable in KM PlotsStack Overflow
版权声明:本文标题:r - How to add legend when we have one grouping variable in KM Plots - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308609a1933722.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论