[R] Change Y-axis labels
David Winsemius
dw|n@em|u@ @end|ng |rom comc@@t@net
Wed Sep 4 23:00:12 CEST 2019
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 (538... using gmail.com)
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.
>
> ______________________________________________
> R-help using r-project.org 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.
More information about the R-help
mailing list