This is a follow on from the previous post, with updated code.
There was an argument ‘groups’ in the ggplot(…) line of the code that was working but is now no longer working with the updated version of R/ggplot2 (I don’t know the full ins and outs of this sorry). So code is fixed and available below.
Most up-to-date code available here: http://pastebin.com/FjkWnCWm
Code originally included in this post: http://pastebin.com/yRmuZtPG
Pingback: Kaplan-Meier Survival Plot – with at risk table « Matt's Stats n stuff
Hi, that’s looking much cleaner than the previous version.
Just trying to workout what your subs parameter is for?
ah, never mind, I missed the 1st version of your function where you go over this at length.
Hy…I still can’t get the code to work.
Thanks for any help
Antonio, I’d be happy to help when I have time. But you’ve given me absolutely nothing to go off… Error message? Are you using your data or just the example from this and my last post?
Hi I am using my data. I have recently updated R. I now have R 2.15.0 (2012-03-30) for Mac and when i run the code I get this error message:
Error in ggkm(fit, timeby = 6, ystratalabs = c(“Calcium salts”, “Sevelamer”), :
could not find function “rbind.fill”
Thanks for al you can tell me.
Antonio
Hi Antonio. Hmm, I can only assume that it’s saying that could there is a package missing. Can you try
install.packages(“plyr”)
And then re run?
THANKS MATT…I DID RELOAD THE PLYR PAKAGE…RE-RUN THE FUNCTION BUT IT STILL DOESN’T WORK…:-(
THANKS ANYWAY
A
Okay. Well I can see from your strata labels that you are using it on your own data. It would be good if you could use the example I used in the post to see if that runs. Then we would know if it was the function on your system that isn’t working or just an anomaly between your data and the function.
Error “could not find function “rbind.fill”” can be fixed by adding following lines under “libraries” in ggkm function:
# libraries #
#############
require(ggplot2)
require(survival)
require(gridExtra)
require(reshape) #rbind.fill function is in this package.
require(plyr) #additional dependency.
################
Hey,
Your function works fine in R 2.14.0 (2011-10-31) now. Unfortunately, it won’t print a p-value anymore, even if I set pval = TRUE
Also, you might consider using pastebin (http://pastebin.com/) to upload your code with, makes it a bit easier imo.
Thanks for the help!
Petra
Also, below
###################################
# specifying plot parameteres etc #
###################################
you have a loose ‘p’ in your code
(line 96)
Thanks Petra, have removed that p that hung around from testing. .
Thanks :) Love your function, keep up the good work!! ^.^
Thanks Petra, have removed the stray p, hang over from fixing the error. The p-value side of it still works for me, however when doing the subgroups the p-value that is used isn’t appropriate, not sure when I’ll get to look at this. Have migrated to pastebin.
Cheers
how about a quick & dirty to avoid reporting wrong p-vals:
if( !is.null(subs) ) pval <- FALSE
Thanks Mark, have added this in the latest version.
Hello Matt,
first of all, great job with your ggkm function. I was searching for a nice function to plot (good looking) survivor curves and your function just fits in.
I have a question about setting the ystratalabs when not given to the function.
if(is.null(ystratalabs)) ystratalabs <- as.character(levels(summary(sfit)$strata)[subs1])
In case on of the strata has no events, so just censored observations, it would not show up in "summary(sfit)". As a consequece your ystratalabs have the wrong length. I got an error when trying the function:
Error in `levels<-.factor`(`*tmp*`, value = "group=G2") :
number of levels differs
Maybe I did something wrong ? Is it possible to set "ystratalabs" to "names(sfit$strata)" or is this the wrong order ?
Best regards,
Stephan
P.S.: Here is a minimal example producing the error above:
surv.table <- data.frame(time=runif(40, min=0, max=12),
status=c(rep(0,20), sample(c(0,1), 20, replace=T)),
group=rep(c("G1", "G2"), each=20)
)
sfit <- survfit(Surv(time, status)~group, data=surv.table)
ggkm(sfit)
Thanks for the post. Sorry for the delay, I didn’t get an email about this until a pingback came through, oddly.
I’ve amended the code down the line you mentioned just adding a sub command to strip out the ‘group=’ from the front. Give it a go. Appreciate a quick reproducible example too! Good luck.
Hello Matt,
now I have to apologize for the late answer. I wasn’t around for some weeks. I tested your new code and it works. Thank you very much! Excellent work!
Stephan
I got an error message as below. Any idea?! Thank you!
> ggkm(fit1)
Error: ggplot2 doesn’t know how to deal with data of class function
Never mind. I just got it through. Thank you!
Pingback: Forest plots in R (ggplot) with side table | Matt's Stats n stuff