-
Notifications
You must be signed in to change notification settings - Fork 164
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
ggsurvplot:: Placing risk table inside survival curves #69
Comments
Maybe stacked barplot on X axis with additional legend on a right (2 legends :P)? |
Good idea!! |
How can I place the risk table inside the plot of the survival curves? Is it possible? If so, I can't find how to do it. |
This is not yet possible. We'll work on it:-)! |
A first attempt of placing risk.table inside survival curves: library(survival)
library(survminer)
fit<- survfit(Surv(time, status) ~ sex, data = lung)
p<-ggsurvplot(fit, data = lung, risk.table = TRUE, risk.table.col = "strata")
# Create a transparent theme object
transparent_theme <- theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank(),
axis.line = element_blank(),
panel.background = element_rect(fill = "transparent",colour = NA),
plot.background = element_rect(fill = "transparent",colour = NA),
plot.margin=unit(c(0,0,0,0),"mm"),)
p1 <- p$plot
p2 <- p$table + transparent_theme
# Create the external graphical elements
# called a "grop" in Grid terminology
p2_grob = ggplotGrob(p2)
p1 + annotation_custom(grob = p2_grob, xmin = -50,
ymin = 0, ymax = 0.25)
I'm not sure that this is good idea... |
It's always just I would go even further and try placing the legend inside the plot oO |
I think that for legend, the job is done using the argument `legend' ggsurvplot(fit, data = lung, risk.table = TRUE, risk.table.col = "strata",
legend = c(0.2, 0.2)) |
Optimal code to be added # Fit survival curves
library(survival)
fit <- survfit( Surv(time, status) ~ rx + adhere, data = colon )
library(survminer)
p <- ggsurvplot(fit, data = lung, risk.table = TRUE, risk.table.col = "strata")
# Create a transparent theme object
transparent_theme <- theme(
title = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank(),
axis.line = element_blank(),
panel.background = element_rect(fill = "transparent",colour = NA),
plot.background = element_rect(fill = "transparent",colour = NA),
plot.margin=unit(c(0,0,0,0),"mm"),
panel.border = element_blank(),
legend.position = "none")
p1 <- p$plot
p2 <- p$table + transparent_theme
# Create the external graphical elements
# called a "grop" in Grid terminology
nstrata = 6
ymax <- nstrata*0.05
p2_grob = ggplotGrob(p2)
p1 + annotation_custom(grob = p2_grob, xmin = -max(fit$time)/20,
ymin = -0.05, ymax = ymax) |
option to add table tick labels on the right side |
New argument library(survival)
fit <- survfit( Surv(time, status) ~ rx + adhere, data = colon )
library(survminer)
ggsurvplot(fit, data = colon,
legend = "right",
pval = TRUE, pval.coord = c(500, 0.4),
risk.table = TRUE, risk.table.y.text = FALSE,
risk.table.pos = "in") |
I like the option to put the risk table inside, but how can I get the table title back? |
How to place risk table inside survival curves?
The text was updated successfully, but these errors were encountered: