Change Y-axis labels

classic Classic list List threaded Threaded
3 messages Options
New
Reply | Threaded
Open this post in threaded view
|

Change Y-axis labels

New
The Y scale is divided (by default) as:
0.0 ... 0.2 ... 0.4 ... 0.6 ... 0.8 ...1.0
But I would like so:
0 ... 20 ... 40 ... 60 ... 80... 100
(with rotating axis labels)
When I use par function (marked as comment here) it turns out
correctly for ONLY ONE picture?! Help me, please. (This is the code
for restricted mean survival time.)

install.packages("survival")
install.packages("survRM2")
library(survival)
library(survRM2)
#automatically creates a sample data
D=rmst2.sample.data()
time=D$time
status=D$status
arm=D$arm
tau=NULL
a=rmst2(time, status, arm, tau=10)
#par(yaxt="n")
plot(a, xlab="Years", ylab="Probability", density=60)
#par(yaxt="s")
#axis(side = 2, at = seq(0, 1, 0.2), labels = seq(0, 100, 20), las = 1)

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Change Y-axis labels

David Winsemius

On 9/4/19 7:35 AM, Medic wrote:

> The Y scale is divided (by default) as:
> 0.0 ... 0.2 ... 0.4 ... 0.6 ... 0.8 ...1.0
> But I would like so:
> 0 ... 20 ... 40 ... 60 ... 80... 100
> (with rotating axis labels)
> When I use par function (marked as comment here) it turns out
> correctly for ONLY ONE picture?! Help me, please. (This is the code
> for restricted mean survival time.)
>
> install.packages("survival")
> install.packages("survRM2")
> library(survival)
> library(survRM2)
> #automatically creates a sample data
> D=rmst2.sample.data()
> time=D$time
> status=D$status
> arm=D$arm
> tau=NULL
> a=rmst2(time, status, arm, tau=10)
> #par(yaxt="n")
> plot(a, xlab="Years", ylab="Probability", density=60)
> #par(yaxt="s")
> #axis(side = 2, at = seq(0, 1, 0.2), labels = seq(0, 100, 20), las = 1)
The plot.rmst2 function has no capacity to accept dots-arguments.

This idea taken from Greg Snow posting from:

Subject:    Re: [R] Add points to subplots
From:    Greg Snow ([hidden email])
Date:    Jun 17, 2014 9:00:44 am
List:    org.r-project.r-help

-----------------------------


draw.first.yax <- function() { par(yaxt="s")
     axis(side = 2, at = seq(0, 1, 0.2), labels = seq(0, 100, 20), las =
1);par(yaxt="n")
}
setHook('before.plot.new', draw.first.yax, "append")  # only plots  axis
in the first subplot
par(yaxt="n")
plot(a, xlab="Years", ylab="Probability", density=60)

setHook('before.plot.new',NULL, 'replace' ) ## clean up

par(yaxt="s");axis(side = 2, at = seq(0, 1, 0.2), labels = seq(0, 100,
20), las = 1) # now plot second axis annotation

--

David.

>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
New
Reply | Threaded
Open this post in threaded view
|

Re: Change Y-axis labels

New
In reply to this post by New
For David Winsemius.
As always, You help out! Immensely grateful!

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.