Re: [R] plot y1 and y2 on one graph

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 27 Feb 2008 17:49:44 -0500

This should do what you want:

x<-1:10
y1<-x+runif(10)*2
y2<-seq(0,50,length.out=10)+rnorm(10)*10

plot(y1~x, bty='c')
par(new=TRUE) # plot on the same graph
plot(y2~x, col='red', axes=FALSE, bty='c', xlab='', ylab='') axis(4, col.axis='red', col='red')
mtext("y2", 4, col='red', line=-2)

On Wed, Feb 27, 2008 at 5:05 PM, milton ruser <milton.ruser_at_gmail.com> wrote:
> Dear all
>
> I have a code like
>
> x<-1:10
> y1<-x+runif(10)*2
> y2<-seq(0,50,length.out=10)+rnorm(10)*10
>
> par(mfrow=c(1,2))
> plot(y1~x)
> plot(y2~x)
>
> Now I would like to plot y1 and y2 on the same graph, with its two scales
> (y1 on left and y2 on rigth side).
>
> Any help are welcome.
>
> Kind regards
>
> Miltinho
>
> Brazil
>
> [[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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?  Tell me what you want to
do, not how you want to do it.

______________________________________________
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.
Received on Wed 27 Feb 2008 - 22:52:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Feb 2008 - 23:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive