-
Hi there -- thanks for such a lovely R package. Was wondering how to further customize ggcuminc graphs with ggplot2 language. See reprex and the example below. Thank you! In this example, I am graphing the incidence of locoregional failure in a cancer population with death as a competing risk factor. In sum, I would like to be able to change the color and line type of each of my levels on the graph, as well as the titles, colors, etc. of the legend and axes. Load librarieslibrary(tidyverse) # organizing and cleaning data Create data frame with sample datadf <- data.frame( Create cuminc functiontest <- cuminc(Surv(ttprog, status) ~ 1, data = df) • Failure type "death without progression" • Failure type "progression" ggcuminc which produces a black-and-white gray curvetest %>% adding ggplot2 language (e.g., to change fill values of lines) produces errorshowever, color argument in the confidence interval workstest %>% test %>% |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Check out the first example in the figure gallery. It provides an example of changing the colors. gg_default <-
[survfit2](http://www.danieldsjoberg.com/ggsurvfit/reference/survfit2.html)([Surv](https://rdrr.io/pkg/survival/man/Surv.html)(time, status) ~ surg, data = df_colon) [%>%](https://magrittr.tidyverse.org/reference/pipe.html)
[ggsurvfit](http://www.danieldsjoberg.com/ggsurvfit/reference/ggsurvfit.html)() +
[add_confidence_interval](http://www.danieldsjoberg.com/ggsurvfit/reference/add_confidence_interval.html)() +
labs(title = "Default")
gg_styled <-
gg_default +
coord_cartesian(xlim = [c](https://rdrr.io/r/base/c.html)(0, 8)) +
scale_y_continuous(
limits = [c](https://rdrr.io/r/base/c.html)(0, 1),
labels = scales::[percent](https://scales.r-lib.org/reference/percent_format.html),
expand = [c](https://rdrr.io/r/base/c.html)(0.01, 0)
) +
scale_x_continuous(breaks = 0:9, expand = [c](https://rdrr.io/r/base/c.html)(0.02, 0)) +
scale_color_manual(values = [c](https://rdrr.io/r/base/c.html)('#54738E', '#82AC7C')) +
scale_fill_manual(values = [c](https://rdrr.io/r/base/c.html)('#54738E', '#82AC7C')) +
theme_minimal() +
theme(legend.position = "bottom") +
guides(color = guide_legend(ncol = 1)) +
labs(
title = "Modified",
y = "Percentage Survival"
)
gg_default + gg_styled |
Beta Was this translation helpful? Give feedback.
-
The code from the gallery works for me: library(ggsurvfit)
#> Loading required package: ggplot2
library(tidycmprsk)
cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
ggcuminc(outcome = "death from cancer") +
add_confidence_interval() +
add_censor_mark() +
add_risktable() +
theme_bw() +
scale_ggsurvfit(x = list(breaks = seq(0, 24, by = 6))) +
scale_color_manual(values = c('#54738E', '#82AC7C')) +
scale_fill_manual(values = c('#54738E', '#82AC7C')) Created on 2022-12-28 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
I have the same question on customizing lines in the The gallery code works to change the line colours if there are two groups (e.g. Drug A and Drug B). However, if there is only one group, but you would like to plot two (or more) outcomes, then it is not clear how to change the line colours. Below examples using 'trial' dataset
Many thanks in advance! |
Beta Was this translation helpful? Give feedback.
-
Hmmm, I am not sure it's possible. The aes is constructed with I am not sure if colors can be modified if there is no call to a color aes? |
Beta Was this translation helpful? Give feedback.
The code from the gallery works for me:
Created on 2022-12-28 with reprex v2.0.2