[R] multiple lines on multiple plots

John Kane jrkrideau at yahoo.ca
Tue Apr 12 19:47:32 CEST 2011


Or perhaps this as an example of using lines() rather than just getting a line and dot output in the upper graph.
  x <- 1:10
 y <- (1:100)*3
 z <- rnorm(100, 150, sd= 75)
 a <- rnorm(10,mean=5, sd= 2.5)
 par(mfcol=c(2,1))
 plot(x)
lines(a, col= "red")
plot(y)
lines(z , col="blue")



--- On Tue, 4/12/11, John Kane <jrkrideau at yahoo.ca> wrote:

> From: John Kane <jrkrideau at yahoo.ca>
> Subject: Re: [R] multiple lines on multiple plots
> To: r-help at r-project.org, "James Annan" <jdannan at jamstec.go.jp>
> Received: Tuesday, April 12, 2011, 11:54 AM
> Try this.
> 
> =======================
> x<- 1:10
> y<- (1:100)*3
> par(mfcol=c(2,1))
> plot(x, type="o")
> plot(y)
> =======================
> 
> 
> 
> --- On Tue, 4/12/11, James Annan <jdannan at jamstec.go.jp>
> wrote:
> 
> > From: James Annan <jdannan at jamstec.go.jp>
> > Subject: [R] multiple lines on multiple plots
> > To: r-help at r-project.org
> > Received: Tuesday, April 12, 2011, 9:30 AM
> > I'm sure this must be trivial, but
> > I'm a novice with R and can't work out how to handle
> the
> > axes when I am constructing multiple plots on a page
> and try
> > to return to a previous one to put multiple data sets
> it.
> > 
> > A simple example:
> > ---
> > x<- 1:10
> > y<- (1:100)*3
> > par(mfcol=c(2,1))
> > plot(x)
> > plot(y)
> > 
> > par(mfg=c(1,1))
> > lines(x)
> > ---
> > 
> > The first 5 lines make two plots with a row of dots
> along
> > the diagonal of each. I intended the last two
> statements to
> > add a line to the first plot, that runs along the same
> data
> > points already plotted there. However, although the
> commands
> > add a line to the top plot, it is clearly using the
> axis
> > dimensions of the lower plot. Can someone tell me how
> to get
> > it to use the axes that are already there?
> > 
> > Variants like lines(x,xlim=c(1,10)) have no effect.
> > 
> > Thanks in advance for any help.
> > 
> > James
> > -- James D Annan jdannan at jamstec.go.jp
> > Tel: +81-45-778-5618 (Fax 5707)
> > Senior Scientist, Research Institute for Global
> Change,
> > JAMSTEC
> > (The Institute formerly known as Frontier)
> > Yokohama Institute for Earth Sciences, 3173-25
> Showamachi,
> > Kanazawa-ku, Yokohama City, Kanagawa, 236-0001 Japan
> > http://www.jamstec.go.jp/frcgc/research/d5/jdannan/
> > 
> > ______________________________________________
> > 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.
> >
> 
> ______________________________________________
> 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.
>



More information about the R-help mailing list