Hi
I am a new fan of R after getting mad with the graphical functional in SPSS.
I have been able to create a nice looking Kaplan Meyer graph using Survplot
function.
However I have difficulties in turning the y axis to percent instead of the
default 0-1 scale.
Further I have tried the function yaxt="n" without any results. Any help in
this matter will be appreciated.
The code is posted below:
par(mfrow=c(1,1))
fit <- survfit(Surv(revreg$Tcuprev , revreg$Rcup_n_j_n)~revreg$RAceGrp_1Maz)
fit
survplot (fit, col=c("gray1","gray40"), lty=1, lwd = 1,
col.fill=c("gray50","gray80"),
mark.time= T, conf="bands" , conf.int=.95, add=F ,
xlim=c(0, 20) , time.inc = 4,
ylim=c(0.5, 1),
xlab="Years Postoperative" , ylab="Cumulative Survival
Probability" ,
label.curves=F , abbrev.label=F ,
yaxt="n"
)
--
View this message in context: http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572.html
Sent from the R help mailing list archive at Nabble.com.
Survplot, Y-axis in percent
9 messages · maziar.mohaddes, David Winsemius, Andrews, Chris +1 more
On Nov 6, 2012, at 8:10 AM, maziar.mohaddes wrote:
Hi I am a new fan of R after getting mad with the graphical functional in SPSS. I have been able to create a nice looking Kaplan Meyer graph using Survplot function. However I have difficulties in turning the y axis to percent instead of the default 0-1 scale. Further I have tried the function yaxt="n" without any results. Any help in this matter will be appreciated. The code is posted below: par(mfrow=c(1,1)) fit <- survfit(Surv(revreg$Tcuprev , revreg$Rcup_n_j_n)~revreg$RAceGrp_1Maz)
Probably better in the future to supply a data argument and then you formula only needs the column names.
fit
survplot (fit, col=c("gray1","gray40"), lty=1, lwd = 1,
col.fill=c("gray50","gray80"),
mark.time= T, conf="bands" , conf.int=.95, add=F ,
xlim=c(0, 20) , time.inc = 4,
ylim=c(0.5, 1),
xlab="Years Postoperative" , ylab="Cumulative Survival
Probability" ,
label.curves=F , abbrev.label=F ,
yaxt="n"
)
As far as I can see, survplot.survfit (from package rms) is written with base graphics, so you need to suppress the default axis call with yaxt=FALSE, and replace it with your desired values using axis(2, at=..., labels=...). No testing in the absence of data.
View this message in context: http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572.html Sent from the R help mailing list archive at Nabble.com.
You should also realize that Nabble is not Rhelp.
David Winsemius, MD Alameda, CA, USA
As far as I can see, survplot.survfit (from package rms) is written with
base graphics, so you need to suppress the
default axis call with yaxt=FALSE, and replace it with your desired values using axis(2, at=..., labels=...).
Thanks alot for your response. Unfortunately yaxt function does not seem to be supported in survplot (rms package).
You should also realize that Nabble is not Rhelp.
Obviously My post has been malplaced, could u please guide me in where to place to post? Thanks in advance
Maziar Mohaddes, MD Gothenburg, Sweden ______________________________________________ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572p4648615.html Sent from the R help mailing list archive at Nabble.com.
On Nov 6, 2012, at 12:18 PM, maziar.mohaddes wrote:
As far as I can see, survplot.survfit (from package rms) is written with
base graphics, so you need to suppress the
default axis call with yaxt=FALSE, and replace it with your desired values using axis(2, at=..., labels=...).
Thanks alot for your response. Unfortunately yaxt function does not seem to be supported in survplot (rms package).
'yaxt' is not a function, but rather a parameter given to survplot. And I admit I didn't look it up, so the correct call may be yaxt="n". I continue to make that mistake, so this might be an example showing why submitting test data is a good idea.
You should also realize that Nabble is not Rhelp.
Obviously My post has been malplaced, could u please guide me in where to place to post?
At the bottom of every posting to Rhelp are two links: One to the Posting Guide: http://www.R-project.org/posting-guide.html The other to the page with information and links to support subscriptions and choices for delivery: https://stat.ethz.ch/mailman/listinfo/r-help
Thanks in advance -- Maziar Mohaddes, MD Gothenburg, Sweden
______________________________________________ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572p4648615.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD Alameda, CA, USA
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121106/b12bb5c0/attachment.pl>
On Nov 6, 2012, at 1:39 PM, maziar.mohaddes wrote:
Thanks alot for ur help. Sorry about me be being a real rookie in forum manners. I am pretty new to R and although i did read the forum rules before submitting obvoiusly I was not able to I did try the yaxt=n, as stated in my post. I wouldn't mind sharing my data but I figure it might be easier to have a dataset which is less messed up than the original data.
Why not use the data in examples on the help page?
David. > I have now subscribed with the mailing list. > > -- > Best regards > Maziar Mohaddes, MD > Gothenburg, Sweden > > On Tue, Nov 6, 2012 at 10:32 PM, David Winsemius [via R] < > ml-node+s789695n4648633h24 at n4.nabble.com> wrote: > >> >> On Nov 6, 2012, at 12:18 PM, maziar.mohaddes wrote: >> >>>> As far as I can see, survplot.survfit (from package rms) is written >> with >>> base graphics, so you need to suppress the >>>> default axis call with yaxt=FALSE, and replace it with your desired >>>> values using axis(2, at=..., labels=...). >>> Thanks alot for your response. Unfortunately yaxt function does not seem >> to >>> be supported in survplot (rms package). >> >> 'yaxt' is not a function, but rather a parameter given to survplot. And I >> admit I didn't look it up, so the correct call may be yaxt="n". I continue >> to make that mistake, so this might be an example showing why submitting >> test data is a good idea. >> >> >>> >>>> You should also realize that Nabble is not Rhelp. >>> Obviously My post has been malplaced, could u please guide me in where >> to >>> place to post? >> >> At the bottom of every posting to Rhelp are two links: >> >> One to the Posting Guide: >> >> http://www.R-project.org/posting-guide.html >> >> The other to the page with information and links to support subscriptions >> and choices for delivery: >> >> https://stat.ethz.ch/mailman/listinfo/r-help >> >> >>> >>> Thanks in advance >>> -- >>> Maziar Mohaddes, MD >>> Gothenburg, Sweden >>> >>> ______________________________________________ >>> R-help@ mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> >>> >>> >>> -- >>> View this message in context: >> http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572p4648615.html >> >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> [hidden email] <http://user/SendEmail.jtp?type=node&node=4648633&i=0>mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> and provide commented, minimal, self-contained, reproducible code. >> >> David Winsemius, MD >> Alameda, CA, USA >> >> ______________________________________________ >> [hidden email] <http://user/SendEmail.jtp?type=node&node=4648633&i=1>mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the discussion >> below: >> >> http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572p4648633.html >> To unsubscribe from Survplot, Y-axis in percent, click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4648572&code=bWF6aWFyLm1vaGFkZGVzQGdtYWlsLmNvbXw0NjQ4NTcyfC0xNzg3NDY3NDQ4> >> . >> NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> > > > > > ----- > Maziar Mohaddes, MD > Gothenburg, Sweden > -- > View this message in context: http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572p4648636.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA
It doesn't look like 'survplot' allows you to control the yaxis formatting in that way. You can edit the function survplot.survfit directly if you really need to: fix(survplot.survfit). The relevant line to change is (I believe) mgp.axis(2, at = pretty(ylim)) to mgp.axis(2, at = pretty(ylim), labels= 100*pretty(ylim)). However, if you are new to R this could cause you more trouble than you want.
Alternatively, you can use 'plot' with the yaxt="n" option. e.g.,
mod <- survfit(Surv(time,status)~ph.ecog, data=lung)
plot(mod, yaxt="n", col=1:4, ylab="Survival Percent", xlab="Days", main="Lung Cancer Data\nEffect of ph.ecog on Survival")
axis(2, at=seq(0,1,0.2), labels=paste(seq(0,100,20), "%", sep=""), las=1)
But that doesn't have all the other stuff you appear to want (e.g., shaded confidence bands).
Good luck,
Chris
-----Original Message-----
From: maziar.mohaddes [mailto:maziar.mohaddes at gmail.com]
Sent: Tuesday, November 06, 2012 11:11 AM
To: r-help at r-project.org
Subject: [R] Survplot, Y-axis in percent
Hi
I am a new fan of R after getting mad with the graphical functional in SPSS.
I have been able to create a nice looking Kaplan Meyer graph using Survplot function.
However I have difficulties in turning the y axis to percent instead of the default 0-1 scale.
Further I have tried the function yaxt="n" without any results. Any help in this matter will be appreciated.
The code is posted below:
par(mfrow=c(1,1))
fit <- survfit(Surv(revreg$Tcuprev , revreg$Rcup_n_j_n)~revreg$RAceGrp_1Maz)
fit
survplot (fit, col=c("gray1","gray40"), lty=1, lwd = 1, col.fill=c("gray50","gray80"),
mark.time= T, conf="bands" , conf.int=.95, add=F ,
xlim=c(0, 20) , time.inc = 4,
ylim=c(0.5, 1),
xlab="Years Postoperative" , ylab="Cumulative Survival Probability" ,
label.curves=F , abbrev.label=F ,
yaxt="n"
)
--
View this message in context: http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572.html
Sent from the R help mailing list archive at Nabble.com.
**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues
Don't change the code. Just use survplot(..., fun=function(y)100*y, ylim=c(0,100)). But note that percent is not recommended as it is more confusing than proportions, especially when talking about differences in percents. Frank Andrews, Chris wrote
It doesn't look like 'survplot' allows you to control the yaxis formatting in that way. You can edit the function survplot.survfit directly if you really need to: fix(survplot.survfit). The relevant line to change is (I believe) mgp.axis(2, at = pretty(ylim)) to mgp.axis(2, at = pretty(ylim), labels= 100*pretty(ylim)). However, if you are new to R this could cause you more trouble than you want. Alternatively, you can use 'plot' with the yaxt="n" option. e.g., mod <- survfit(Surv(time,status)~ph.ecog, data=lung) plot(mod, yaxt="n", col=1:4, ylab="Survival Percent", xlab="Days", main="Lung Cancer Data\nEffect of ph.ecog on Survival") axis(2, at=seq(0,1,0.2), labels=paste(seq(0,100,20), "%", sep=""), las=1) But that doesn't have all the other stuff you appear to want (e.g., shaded confidence bands). Good luck, Chris -----Original Message----- From: maziar.mohaddes [mailto:
maziar.mohaddes@
] Sent: Tuesday, November 06, 2012 11:11 AM To:
r-help@
Subject: [R] Survplot, Y-axis in percent
Hi
I am a new fan of R after getting mad with the graphical functional in
SPSS.
I have been able to create a nice looking Kaplan Meyer graph using
Survplot function.
However I have difficulties in turning the y axis to percent instead of
the default 0-1 scale.
Further I have tried the function yaxt="n" without any results. Any help
in this matter will be appreciated.
The code is posted below:
par(mfrow=c(1,1))
fit <- survfit(Surv(revreg$Tcuprev ,
revreg$Rcup_n_j_n)~revreg$RAceGrp_1Maz)
fit
survplot (fit, col=c("gray1","gray40"), lty=1, lwd = 1,
col.fill=c("gray50","gray80"),
mark.time= T, conf="bands" , conf.int=.95, add=F ,
xlim=c(0, 20) , time.inc = 4,
ylim=c(0.5, 1),
xlab="Years Postoperative" , ylab="Cumulative Survival
Probability" ,
label.curves=F , abbrev.label=F ,
yaxt="n"
)
--
View this message in context:
http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572.html
Sent from the R help mailing list archive at Nabble.com.
**********************************************************
Electronic Mail is not secure, may not be read every day, and should not
be used for urgent or sensitive issues
______________________________________________
R-help@
mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
----- Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572p4648697.html Sent from the R help mailing list archive at Nabble.com.
Dear Prof Harell, great thanks for your solution to this. I have been trying to figure this out last four weeks by reading loads of manuals and forums around the net without success. Once again thank you for the solution and the great option of shadowed Conf int in the survplot Best Regards ----- Maziar Mohaddes, MD Gothenburg, Sweden -- View this message in context: http://r.789695.n4.nabble.com/Survplot-Y-axis-in-percent-tp4648572p4648703.html Sent from the R help mailing list archive at Nabble.com.