Re: [R] multiple lines on multiple plots

2011-04-18 Thread Greg Snow
Going back to a previous graph does not automatically restore the coordinate 
system (as you noticed).  But you can store that information (lot less info 
than your data in most cases) and reset it manually.  Try:

x- 1:10
y- (1:100)*3
par(mfcol=c(2,1))
plot(x)
tmp1 - par('usr')
plot(y)
tmp2 - par('usr')

par(mfg=c(1,1))
par(usr=tmp1)
lines(x)
par(mfg=c(2,1))
par(usr=tmp2)
lines(y)


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of James Annan
 Sent: Tuesday, April 12, 2011 11:06 PM
 To: jim holtman
 Cc: r-help@r-project.org
 Subject: Re: [R] multiple lines on multiple plots
 
 Thanks for all the replies. Yes, I agree that calculating all the data
 first is a simple solution which also has the benefit of making the
 axis
 choice easier to get right, but on the downside it requires storing an
 order of magnitude more output than my original sequential approach
 would have done. Not actually a problem for me right now, but may be
 for
 larger cases and certainly seems inelegant in general. So I'm still
 interested to know if there is some practical way of returning to an
 earlier plot. I suppose I could artificially scale the data to make it
 match the wrong axes. But that would be horrible.
 
 (The example was deliberately simple, but in reality I want to loop
 through a bunch of simple simulations each of which generates several
 types of output, and create a graph for each type of output.)
 
 James
 
 On 13/4/11 1:25 AM, jim holtman wrote:
  Instead of trying to go back to a previous plot, gather up all the
  data for the plots and generate each one with the appropriate data.
  This is much easier than trying to keep track of what the dimensions
  are.  Also if the data you want to add is outside the plot, then you
  have issues with clipping; knowing what the dimensions of all the
 data
  you want to plot is a reasonable way to go.
 
  On Tue, Apr 12, 2011 at 9:30 AM, James Annanjdan...@jamstec.go.jp
 wrote:
  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 jdan...@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@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.
 
 
 
 
 
 
 --
 James D Annan jdan...@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@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@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.


Re: [R] multiple lines on multiple plots

2011-04-18 Thread James Annan
Thanks! I'd seen this sort of trick mentioned in places, but didn't twig 
what it did. This is exactly what I was looking for.


James

On 19/4/11 7:04 AM, Greg Snow wrote:


tmp1- par('usr')


--
James D Annan jdan...@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@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] multiple lines on multiple plots

2011-04-12 Thread James Annan
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 jdan...@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@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.


Re: [R] multiple lines on multiple plots

2011-04-12 Thread John Kane
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 jdan...@jamstec.go.jp wrote:

 From: James Annan jdan...@jamstec.go.jp
 Subject: [R] multiple lines on multiple plots
 To: r-help@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 jdan...@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@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@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.


Re: [R] multiple lines on multiple plots

2011-04-12 Thread jim holtman
Instead of trying to go back to a previous plot, gather up all the
data for the plots and generate each one with the appropriate data.
This is much easier than trying to keep track of what the dimensions
are.  Also if the data you want to add is outside the plot, then you
have issues with clipping; knowing what the dimensions of all the data
you want to plot is a reasonable way to go.

On Tue, Apr 12, 2011 at 9:30 AM, James Annan jdan...@jamstec.go.jp wrote:
 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 jdan...@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@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
Data Munger Guru

What is the problem that you are trying to solve?

__
R-help@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.


Re: [R] multiple lines on multiple plots

2011-04-12 Thread John Kane
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 jrkrid...@yahoo.ca wrote:

 From: John Kane jrkrid...@yahoo.ca
 Subject: Re: [R] multiple lines on multiple plots
 To: r-help@r-project.org, James Annan jdan...@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 jdan...@jamstec.go.jp
 wrote:
 
  From: James Annan jdan...@jamstec.go.jp
  Subject: [R] multiple lines on multiple plots
  To: r-help@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 jdan...@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@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@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@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.


Re: [R] multiple lines on multiple plots

2011-04-12 Thread James Annan
Thanks for all the replies. Yes, I agree that calculating all the data 
first is a simple solution which also has the benefit of making the axis 
choice easier to get right, but on the downside it requires storing an 
order of magnitude more output than my original sequential approach 
would have done. Not actually a problem for me right now, but may be for 
larger cases and certainly seems inelegant in general. So I'm still 
interested to know if there is some practical way of returning to an 
earlier plot. I suppose I could artificially scale the data to make it 
match the wrong axes. But that would be horrible.


(The example was deliberately simple, but in reality I want to loop 
through a bunch of simple simulations each of which generates several 
types of output, and create a graph for each type of output.)


James

On 13/4/11 1:25 AM, jim holtman wrote:

Instead of trying to go back to a previous plot, gather up all the
data for the plots and generate each one with the appropriate data.
This is much easier than trying to keep track of what the dimensions
are.  Also if the data you want to add is outside the plot, then you
have issues with clipping; knowing what the dimensions of all the data
you want to plot is a reasonable way to go.

On Tue, Apr 12, 2011 at 9:30 AM, James Annanjdan...@jamstec.go.jp  wrote:

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 jdan...@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@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.








--
James D Annan jdan...@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@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.


Re: [R] multiple lines on multiple plots

2011-04-12 Thread baptiste auguie
Hi,

ggplot2 automatically adjusts its axes when new data are added to
plots; however you wouldn't get an automatic legend if you constructed
plots that way.

HTH,

baptiste

On 13 April 2011 17:06, James Annan jdan...@jamstec.go.jp wrote:
 Thanks for all the replies. Yes, I agree that calculating all the data first
 is a simple solution which also has the benefit of making the axis choice
 easier to get right, but on the downside it requires storing an order of
 magnitude more output than my original sequential approach would have done.
 Not actually a problem for me right now, but may be for larger cases and
 certainly seems inelegant in general. So I'm still interested to know if
 there is some practical way of returning to an earlier plot. I suppose I
 could artificially scale the data to make it match the wrong axes. But that
 would be horrible.

 (The example was deliberately simple, but in reality I want to loop through
 a bunch of simple simulations each of which generates several types of
 output, and create a graph for each type of output.)

 James

 On 13/4/11 1:25 AM, jim holtman wrote:

 Instead of trying to go back to a previous plot, gather up all the
 data for the plots and generate each one with the appropriate data.
 This is much easier than trying to keep track of what the dimensions
 are.  Also if the data you want to add is outside the plot, then you
 have issues with clipping; knowing what the dimensions of all the data
 you want to plot is a reasonable way to go.

 On Tue, Apr 12, 2011 at 9:30 AM, James Annanjdan...@jamstec.go.jp
  wrote:

 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 jdan...@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@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.






 --
 James D Annan jdan...@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@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@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.