[R] Two plots with two different Y labels

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Thu Mar 1 09:32:42 CET 2012

Try this:

x <- 1:5
y1 <- rnorm(5)
y2 <- rnorm(5)
par(mar = c(5,4,5,4))
plot(x, y1, xlab = "x-axis", ylab = "y-axis", type = "l")
par(new = TRUE)
plot(x, y2, axes = FALSE, yaxs = "i", type = "l",
     ann = FALSE, col = 2)
axis(4, las = 2)
mtext("z-axis", 4, 2)

I hope it helps.


On 3/1/2012 9:13 AM, Alaios wrote:
> Dear all,
> I would like to place into a same plot two plots. Their y values though are different a lot (first series has around -100 y values and the second one slightly over 1). The x value are the same.
> I would like to have in the same plot (under the same x,y axis the two plots). Is it possible then to have two y labels, one for example in the left side and an extra y label at the right. Each y label will have its own labeling and its own Font type line.
> CAn I do something like that in R with the normal plots and lines?
> I would like to thank you in advance for your help
> B.R
> Alex
> 	[[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.

Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/

More information about the R-help mailing list