-
Notifications
You must be signed in to change notification settings - Fork 168
cens count graph under risk table #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The final ggsurvplot would look like this: library(RTCGA)
library(RTCGA.clinical)
library(survminer)
BRCAOV.survInfo <- survivalTCGA(BRCA.clinical, OV.clinical,
extract.cols = "admin.disease_code")
# Survival curves + risk table
fit <- survfit(Surv(times, patient.vital_status)~admin.disease_code,
data = BRCAOV.survInfo)
surv.curv <- ggsurvplot(fit, pval = TRUE, conf.int = TRUE,
risk.table = TRUE, legend.labs = c("brca", "ov"))
# n.censor.plot
d <- data.frame(time = fit$time,
n.censor = fit$n.censor,
strata = as.factor(rep(names(fit$strata), fit$strata)))
ncensor.plot <- ggplot(d, aes(time, n.censor)) +
geom_bar(aes(color = strata, fill = strata), stat = "identity", position = "dodge") +
theme_classic() + theme(legend.position = "none")
# Arrange plots
gridExtra::grid.arrange(surv.curv$plot, surv.curv$table, ncensor.plot, heights = c(0.5, 0.25, 0.25)) Do you have any suggestion about the plot? |
@prostkop what do You think about that :)? |
cens.density = FALSE by defualt :) for me it looks interesting. I am wondering whether bars could be replaced with geom_denisty? What do You think? And You @prostkop? Marcin Kosinski Dnia 25.02.2016 o godz. 13:10 Alboukadel KASSAMBARA notifications@github.com napisał(a):
|
I think this 3rd plot should have the same width of axis as the first 2 containing survival curves and risk table |
Definitely, last plot should be in line with others. In addition, on the 3rd plot number of censoring is hardly visible, because of a peak in the beginning of the study. Maybe, some "algorithm" should be applied to mark "outlying" bars and decrease their heights. But essentially, it is very nice plot :) |
And in my opinion colours of the last plot should vary from the colours of the survival curves, so to avoid confusion :) |
Yes, I completely agree with you!! This was a quick arrangement of the plots for discussion... I'll work in the script to improve the final output! Thanks :)! |
Hey, have you tried working on that :)? |
Hi Marcin, I think that plotting the number of censor events, at each time point, can be really unreadable in a situation where you have a large cohort of patients with multiple groups. For example (option 1): library(survival)
library(survminer)
fit <- survfit( Surv(time, status) ~ rx + adhere,
data = colon )
surv.curv <- ggsurvplot(fit, risk.table = TRUE, risk.table.col = "strata",
break.time.by = 500)
surv.curv The plot of censor events: # ncensor data
d <- data.frame(time = fit$time,
n.censor = fit$n.censor,
strata = as.factor(rep(names(fit$strata), fit$strata)))
ggplot(d, aes(time, n.censor)) +
geom_bar(aes(color = strata, fill = strata), stat = "identity", position = "dodge") +
theme_bw() +
ggplot2::theme(legend.position = "none") However, we can plot the number of censor event at specific time points to make the plot more readable (option 2): times <- ggplot_build(surv.curv$plot)$panel$ranges[[1]]$x.major_source
# n.censor.plot
fit_summary <- summary(fit, times = times, extend = TRUE)
d <- data.frame(time = as.factor(fit_summary$time),
n.censor = fit_summary$n.censor,
strata = factor(fit_summary$strata)
)
# bar plot of censor events
ggplot(d, aes(time, n.censor)) +
geom_bar(aes(color = strata, fill = strata), stat = "identity", position = "dodge") +
theme_classic() +
ggplot2::theme(legend.position = "none")
# line plot of censor events
d$time <- fit_summary$time
ggplot(d, aes(time, n.censor)) +
geom_line(aes(color = strata))+
theme_classic() +
ggplot2::theme(legend.position = "none") Bar plot: Line plot: The final plot would look like as follow: # censor plot
cens.plot <- ggplot(d, aes(time, n.censor)) +
geom_line(aes(color = strata))+
theme_classic() +
ggplot2::theme(legend.position = "none")+
coord_cartesian(xlim = c(0, max(fit$time))) +
ggplot2::scale_x_continuous(breaks = times)+
theme(legend.key.height = NULL, legend.key.width = NULL,
legend.key = element_rect(colour = NA, fill = NA),
legend.text = element_text(colour = NA),
legend.title = element_text(colour = NA)) +
guides(color = FALSE)
# Arrange plots
x <- list(ncensor = cens.plot, table = surv.curv$table, plot = surv.curv$plot)
plots <- rev(x)
grobs <- widths <- list()
for (i in 1:length(plots)) {
grobs[[i]] <- ggplotGrob(plots[[i]])
widths[[i]] <- grobs[[i]]$widths[2:5]
}
maxwidth <- do.call(grid::unit.pmax, widths)
for (i in 1:length(grobs)) {
grobs[[i]]$widths[2:5] <- as.list(maxwidth)
}
do.call(gridExtra::grid.arrange, c(grobs, nrow = 3, heights = list(c(0.5, 0.25, 0.25)))) What do you think about option 2? |
I think line plot and barplot are great ideas :) There could be a parameter @prostkop do you have any suggestions? |
Ok! I'm adding these options in ggsurvplot function:-)! |
Great! Thanks :) 2016-03-23 17:26 GMT+01:00 Alboukadel KASSAMBARA notifications@github.com:
|
Sorry for a litle delay. Indeed, plot looks really tidy and nice. I don't have time to run your example, but do you choose some specific time points for n.cesoring plot and between these points linear interpolations is used ? How about using all time points with censoring ? Probably, plot will be more irregular, but maybe more reliable ? |
@kassambara can we close this issue? Is that feature avaiable? |
Hi!! |
Wow, this looks great. Can you explain how this was created and is it the
I know I've mentioned a lot of topics. You can split answers to separate PS. Have you thought about attending eRum :) http://erum.ue.poznan.pl/? 2016-04-22 0:04 GMT+02:00 Alboukadel KASSAMBARA notifications@github.com:
|
I used the R package staticdocs, developed by Hadley Wickham, to build survminer documentation website. ggplot2 online documentation has been built using the same package. The job is simply done using the following R code: staticdocs::build_site(pkg = "local/path/to/survminer", site_path = "path/to/site/directory")
PS. I'm not sure to attend eRum Best, |
I think this is still an interesting feature and we could think about it in ver 0.2.3 ? :) |
New argument 'ncensor.plot' added to require("survival")
fit<- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit, risk.table = TRUE, ncensor.plot = TRUE, risk.table.height = 0.35) |
Marvelous :) Keep going @kassambara |
Once I've seen an interesting idea of adding counts of censored observation through time.
@prostkop have prepared such graph on a lecture
Technics of Data Visualizations
(held on Warsaw University of Technology) https://github.com/pbiecek/TechnikiWizualizacjiDanych/blob/master/MINI_MIMUW_2014/Miniaturka/Faza%203/Szewczyk_Prostko_Ryciak_Ryciuk/3.pngI think it could be a good additional feedback to survival curves, so that one could realize: how do survival curves look like, what is the number of risk set AND what is the cause that the risk set become smaller: is it caused by events or by censored events ?
So the final ggsurvplot could consist of 3 plots: KM-curves, risk.table + cens density/barplot?
The text was updated successfully, but these errors were encountered: