dear all, I want to plot a kaplan Meier plot with the following functions, but I fail to produce the plot I want: library(survival) tim <- (1:50)/6 ind <- runif(50) ind[ind > 0.5] <- 1; ind[ind < 0.5] <- 0; MS <- runif(50) pred <- vector() pred[MS < 0.3] <- 0; pred[MS >= 0.3] <- 1 df <- as.data.frame(cbind(MS, tim, pred, ind)) names(df) <- c("MS", "time", "pred", "class") df$time[df$time > 6] <- 6 surv <- Surv(as.numeric(as.vector(df$time)), as.numeric(as.vector(df$class))) dfPval <- summary(coxph(Surv(as.numeric(as.vector(df$time)), as.numeric(as.vector(df$class))) ~ pred, df))$sctest par(mfrow = c(2,2)) plot(survfit(surv ~ df$pred), col=c("red","green"), ylab = "percentage of survival", xlab = "survival years") plot(survfit(surv ~ df$pred), col=c("red","green"), lwd = 8, ylab "percentage of survival", xlab = "survival years") plot(survfit(surv ~ df$pred), col=c("red","green"), lwd = 8, ylab "percentage of survival", xlab = "survival years", cex = 2) I would like to increase the tickness of the censorship's pitch. as you can see with cex = 2, I can elongate the arms of the censorship, but I cant find how to increase the tickness of the pitch. how to do this? [[alternative HTML version deleted]]
dear all, I want to plot a kaplan Meier plot with the following functions, but I fail to produce the plot I want: library(survival) tim <- (1:50)/6 ind <- runif(50) ind[ind > 0.5] <- 1; ind[ind < 0.5] <- 0; MS <- runif(50) pred <- vector() pred[MS < 0.3] <- 0; pred[MS >= 0.3] <- 1 df <- as.data.frame(cbind(MS, tim, pred, ind)) names(df) <- c("MS", "time", "pred", "class") df$time[df$time > 6] <- 6 surv <- Surv(as.numeric(as.vector(df$time)), as.numeric(as.vector(df$class))) dfPval <- summary(coxph(Surv(as.numeric(as.vector(df$time)), as.numeric(as.vector(df$class))) ~ pred, df))$sctest par(mfrow = c(2,2)) plot(survfit(surv ~ df$pred), col=c("red","green"), ylab = "percentage of survival", xlab = "survival years") plot(survfit(surv ~ df$pred), col=c("red","green"), lwd = 8, ylab "percentage of survival", xlab = "survival years") plot(survfit(surv ~ df$pred), col=c("red","green"), lwd = 8, ylab "percentage of survival", xlab = "survival years", cex = 2) I would like to increase the tickness of the censorship's pitch. as you can see with cex = 2, I can elongate the arms of the censorship, but I cant find how to increase the tickness of the pitch. how to do this? [[alternative HTML version deleted]]
on 01/14/2009 03:32 PM John Lande wrote:> dear all, > > I want to plot a kaplan Meier plot with the following functions, but I fail > to produce the plot I want: > > library(survival) > tim <- (1:50)/6 > ind <- runif(50) > ind[ind > 0.5] <- 1; ind[ind < 0.5] <- 0; > MS <- runif(50) > pred <- vector() > pred[MS < 0.3] <- 0; pred[MS >= 0.3] <- 1 > df <- as.data.frame(cbind(MS, tim, pred, ind)) > names(df) <- c("MS", "time", "pred", "class") > df$time[df$time > 6] <- 6 > surv <- Surv(as.numeric(as.vector(df$time)), > as.numeric(as.vector(df$class))) > dfPval <- summary(coxph(Surv(as.numeric(as.vector(df$time)), > as.numeric(as.vector(df$class))) ~ pred, df))$sctest > par(mfrow = c(2,2)) > plot(survfit(surv ~ df$pred), col=c("red","green"), ylab = "percentage of > survival", xlab = "survival years") > plot(survfit(surv ~ df$pred), col=c("red","green"), lwd = 8, ylab > "percentage of survival", xlab = "survival years") > plot(survfit(surv ~ df$pred), col=c("red","green"), lwd = 8, ylab > "percentage of survival", xlab = "survival years", cex = 2) > > I would like to increase the tickness of the censorship's pitch. as you can > see with cex = 2, I can elongate the arms of the censorship, but I cant find > how to increase the tickness of the pitch. > > how to do this?John, Is this what you want? par(mfrow = c(2, 1)) # Normal plot plot(survfit(Surv(time, status) ~ x, data = aml)) # Set par(lwd = 3) to increase the thickness of the censoring marks # Don't frame the plot region, as it uses par(lwd) par(lwd = 3) plot(survfit(Surv(time, status) ~ x, data = aml), frame = FALSE) # Reset par(lwd) to normal to frame the plot region par(lwd = 1) box() Note that given the way in which the plot code has been set up, using 'lwd' in the function call affects the survivorship function line and not the censoring marks. By setting par(lwd = 3) prior to the plot call, this will be used internally when the marks are plotted using points(), without affecting the other lines, save the plot region frame. Just so that you don't think that you missed something obvious, this was a little trial and error after reviewing the R code for survival:::plot.survfit to see how the arguments from the function call are passed to the internal plotting functions. Combined also with some knowledge of how the graphic pars are handled... HTH, Marc Schwartz