Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
numbers at risk on kaplan-meier curve
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gary Collins  
View profile  
 More options May 8 2009, 3:30 am
From: Gary Collins <collins...@gmail.com>
Date: Fri, 08 May 2009 08:30:40 +0100
Local: Fri, May 8 2009 3:30 am
Subject: numbers at risk on kaplan-meier curve
I've been tweaking some lines, from a thread a few weeks ago, trying to
get a decent kaplan-meier curve with numbers at risk printed below the
x-axis.

Two things I'd welcome suggestions on (1) lining up the numbers at risk
with the time points on the k-m curve - it doesn't look to bad on the
screen, but doesn't look right when saved as a pdf and (2) there's a
white box around the legend which I can't seem to figure out how to
remove - unless there are other suggestions to prettify the legend.

I'm trying to generalise as much as possible and minimise on data
dependent tweaking so that the code would be useable with minimal
changes for different datasets.

Thanks

Gary

The code to reproduce the figure is

library(ggplot2)
require(survival)

fit <- survfit(Surv(time, status) ~ rx, data = colon)

df <- data.frame(
   time    = fit$time,
   n.risk  = fit$n.risk,
   n.event = fit$n.event,
   surv    = fit$surv,
   strata  = gsub("rx=", "", summary(fit, censored = T)$strata),
   upper   = fit$upper,
   lower   = fit$lower
)

zeros <- data.frame(time = 0, surv = 1, strata = gsub("rx=", "",
levels(summary(fit)$strata)), upper = 1, lower = 1)

df <- rbind.fill(zeros, df)

p <- ggplot(df, aes(time, surv, colour = strata)) +
        geom_step(size = 0.6) +
        xlim(0, max(fit$time)) +
        ylim(0, 1) +
        xlab("days from randomization") +
        ylab("survival probability") +
        scale_colour_brewer(name = "Treatment", pal = "Set1") +
        opts(legend.position = c(0.9, 0.9)) +
        opts(legend.key = theme_rect(colour = NA))

times <- seq(0, max(fit$time), by = 500)

risk.data <- data.frame(strata = summary(fit, times = times, extend =
T)$strata,
     time = summary(fit, times = times, extend = T)$time,
     n.risk = summary(fit, times = times, extend = T)$n.risk)

data_table <- ggplot(risk.data, aes(x = time, y = strata, label =
format(n.risk, nsmall = 0)), colour = strata) +
     geom_text(size = 3.5) +
     theme_bw() +
     scale_y_discrete(formatter = abbreviate, limits = c("rx=Obs",
"rx=Lev", "rx=Lev+5FU"), labels = c("Obs", "Lev", "Lev+5FU")) +
     opts(panel.grid.major = theme_blank()) +
     opts(panel.grid.minor = theme_blank()) +
     opts(panel.border     = theme_blank()) +
     opts(axis.text.x      = theme_blank()) +
     opts(axis.ticks       = theme_blank()) +
     xlim(0, max(fit$time))

data_table <- data_table + opts(legend.position = "none") + xlab(NULL) +
ylab(NULL)

data_table <- data_table + opts(plot.margin = unit(c(-0.5, 0, 0, -0.75),
"lines"))

# + opts(plot.margin = unit(c(-0.5, 1, 0, 0.5), "lines")) + xlab(NULL) +
ylab(NULL)

Layout <- grid.layout(nrow = 2, ncol = 1,heights = unit (c(2, .25),
c("null", "null")))

vplayout <- function (...) {
     grid.newpage()
     pushViewport(viewport(layout = Layout))

}

subplot <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)
mmplot <- function(a, b) {
     vplayout()
     print(a, vp = subplot(1, 1))
     print(b, vp = subplot(2, 1))

}

#pdf("c:\\test.pdf", pointsize=11, paper="a4r", width=10, height=10)
mmplot(p, data_table)
#dev.off()

---------------------------------------------------------------
Dr Gary S Collins                       Tel: +44 (0)1865 284418
Centre for Statistics in Medicine       Fax: +44 (0)1865 284424
Wolfson College Annexe                    www.csm-oxford.org.uk
University of Oxford
Linton Road
Oxford, OX2 6UD
---------------------------------------------------------------


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xie Chao  
View profile  
 More options May 8 2009, 5:08 am
From: Xie Chao <xiech...@gmail.com>
Date: Fri, 8 May 2009 17:08:09 +0800
Local: Fri, May 8 2009 5:08 am
Subject: Re: numbers at risk on kaplan-meier curve

You can use opts(legend.background = theme_blank()) to remove the white box
around the legend:
mmplot(p+opts(legend.background = theme_blank()), data_table)

Regards,
Xie Chao


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »