Re: [R] Second y-axis --- alternative to par(new=

2009-10-08 Thread jim holtman
What you need to do is to specify that you don't want labels on the second plot:

## (2) Does plot points where (x-axis) they should be
xlim - range(x1)
plot(x1, y1, type=l, xlim=xlim)
par(new=TRUE)
plot(x2, y2, type=p, xlim=xlim, xlab='', ylab='', axes=FALSE)
axis(4)

On Wed, Oct 7, 2009 at 4:29 AM, Rainer M Krug r.m.k...@gmail.com wrote:
 Hi

 is there an alternative to par(new), for ading data to a plot for a
 different y-axis?
 My problem with par(new=TRUE) is, that it re-defines all axis and labels (as
 in example 1) and one has to use xlim=... to fix the x-axis.
 I am looking for something, which simply resets the y-axis, so that a new
 plot() (or points()/lines()) keeps the x-axis, but re-defines the y-axis.

 Is there something available? I could re-scale the y-data to fit the
 existing y-axis, but that would mean to define all the labels and tickmarks
 for axis 4 manually.

 HEre is an example about what I mean:

 x1 - 1:10
 y1 - runif(10)
 x2 - 1:11
 y2 - c(y1*100, 0)

 ## (1) Does not plot points where (x-axis) they should be
 plot(x1, y1, type=l)
 par(new=TRUE)
 plot(x2, y2, type=p)
 axis(4)

 ## (2) Does plot points where (x-axis) they should be
 xlim - range(x1)
 plot(x1, y1, type=l, xlim=xlim)
 par(new=TRUE)
 plot(x2, y2, type=p, xlim=xlim)
 axis(4)

 Cheers,


 Rainer
 --
 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
 UCT), Dipl. Phys. (Germany)

 Centre of Excellence for Invasion Biology
 Natural Sciences Building
 Office Suite 2039
 Stellenbosch University
 Main Campus, Merriman Avenue
 Stellenbosch
 South Africa

 Cell:           +27 - (0)83 9479 042
 Fax:            +27 - (0)86 516 2782
 Fax:            +49 - (0)721 151 334 888
 email:          rai...@krugs.de

 Skype:          RMkrug
 Google:         r.m.k...@gmail.com

        [[alternative HTML version deleted]]

 __
 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
Cincinnati, OH
+1 513 646 9390

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.


[R] Second y-axis --- alternative to par(new=

2009-10-07 Thread Rainer M Krug
Hi

is there an alternative to par(new), for ading data to a plot for a
different y-axis?
My problem with par(new=TRUE) is, that it re-defines all axis and labels (as
in example 1) and one has to use xlim=... to fix the x-axis.
I am looking for something, which simply resets the y-axis, so that a new
plot() (or points()/lines()) keeps the x-axis, but re-defines the y-axis.

Is there something available? I could re-scale the y-data to fit the
existing y-axis, but that would mean to define all the labels and tickmarks
for axis 4 manually.

HEre is an example about what I mean:

x1 - 1:10
y1 - runif(10)
x2 - 1:11
y2 - c(y1*100, 0)

## (1) Does not plot points where (x-axis) they should be
plot(x1, y1, type=l)
par(new=TRUE)
plot(x2, y2, type=p)
axis(4)

## (2) Does plot points where (x-axis) they should be
xlim - range(x1)
plot(x1, y1, type=l, xlim=xlim)
par(new=TRUE)
plot(x2, y2, type=p, xlim=xlim)
axis(4)

Cheers,


Rainer
-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)721 151 334 888
email:  rai...@krugs.de

Skype:  RMkrug
Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]

__
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] Second y-axis --- alternative to par(new=

2009-10-07 Thread Rainer M Krug
On Wed, Oct 7, 2009 at 11:28 AM, Petr PIKAL petr.pi...@precheza.cz wrote:

 Hi

 Try ?twoord.plot from plotrix package.


Thanks Petr - I was not aeware of this command.
But I would prefer a more general solution. An example on where I am using
is, to plot a histogram overlayed by its density estimate (easier to digest
for others then only a density estimate).

And a newY() (or par(newY=TRUE) command would enable exactly this.

Regards,

Rainer



 Regards
 Petr



 r-help-boun...@r-project.org napsal dne 07.10.2009 10:29:53:

  Hi
 
  is there an alternative to par(new), for ading data to a plot for a
  different y-axis?
  My problem with par(new=TRUE) is, that it re-defines all axis and labels
 (as
  in example 1) and one has to use xlim=... to fix the x-axis.
  I am looking for something, which simply resets the y-axis, so that a
 new
  plot() (or points()/lines()) keeps the x-axis, but re-defines the
 y-axis.
 
  Is there something available? I could re-scale the y-data to fit the
  existing y-axis, but that would mean to define all the labels and
 tickmarks
  for axis 4 manually.
 
  HEre is an example about what I mean:
 
  x1 - 1:10
  y1 - runif(10)
  x2 - 1:11
  y2 - c(y1*100, 0)
 
  ## (1) Does not plot points where (x-axis) they should be
  plot(x1, y1, type=l)
  par(new=TRUE)
  plot(x2, y2, type=p)
  axis(4)
 
  ## (2) Does plot points where (x-axis) they should be
  xlim - range(x1)
  plot(x1, y1, type=l, xlim=xlim)
  par(new=TRUE)
  plot(x2, y2, type=p, xlim=xlim)
  axis(4)
 
  Cheers,
 
 
  Rainer
  --
  Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
 Biology,
  UCT), Dipl. Phys. (Germany)
 
  Centre of Excellence for Invasion Biology
  Natural Sciences Building
  Office Suite 2039
  Stellenbosch University
  Main Campus, Merriman Avenue
  Stellenbosch
  South Africa
 
  Cell:   +27 - (0)83 9479 042
  Fax:+27 - (0)86 516 2782
  Fax:+49 - (0)721 151 334 888
  email:  rai...@krugs.de
 
  Skype:  RMkrug
  Google: r.m.k...@gmail.com
 
 [[alternative HTML version deleted]]
 
  __
  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.




-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)721 151 334 888
email:  rai...@krugs.de

Skype:  RMkrug
Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]

__
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] Second y-axis --- alternative to par(new=

2009-10-07 Thread Petr PIKAL
r-help-boun...@r-project.org napsal dne 07.10.2009 11:37:22:

 On Wed, Oct 7, 2009 at 11:28 AM, Petr PIKAL petr.pi...@precheza.cz 
wrote:
 
  Hi
 
  Try ?twoord.plot from plotrix package.
 
 
 Thanks Petr - I was not aeware of this command.
 But I would prefer a more general solution. An example on where I am 
using
 is, to plot a histogram overlayed by its density estimate (easier to 
digest
 for others then only a density estimate).

That is quite different from your example. I believe overlay of density 
curve over histogram was discussed several times e.g. 
http://tolstoy.newcastle.edu.au/R/e4/help/08/06/14198.html 

 
 And a newY() (or par(newY=TRUE) command would enable exactly this.

This is something beyond my knowledge and it could be that this need some 
deep redefining in base R graphics.

Regards
Petr

 
 Regards,
 
 Rainer
 
 
 
  Regards
  Petr
 
 
 
  r-help-boun...@r-project.org napsal dne 07.10.2009 10:29:53:
 
   Hi
  
   is there an alternative to par(new), for ading data to a plot for a
   different y-axis?
   My problem with par(new=TRUE) is, that it re-defines all axis and 
labels
  (as
   in example 1) and one has to use xlim=... to fix the x-axis.
   I am looking for something, which simply resets the y-axis, so that 
a
  new
   plot() (or points()/lines()) keeps the x-axis, but re-defines the
  y-axis.
  
   Is there something available? I could re-scale the y-data to fit the
   existing y-axis, but that would mean to define all the labels and
  tickmarks
   for axis 4 manually.
  
   HEre is an example about what I mean:
  
   x1 - 1:10
   y1 - runif(10)
   x2 - 1:11
   y2 - c(y1*100, 0)
  
   ## (1) Does not plot points where (x-axis) they should be
   plot(x1, y1, type=l)
   par(new=TRUE)
   plot(x2, y2, type=p)
   axis(4)
  
   ## (2) Does plot points where (x-axis) they should be
   xlim - range(x1)
   plot(x1, y1, type=l, xlim=xlim)
   par(new=TRUE)
   plot(x2, y2, type=p, xlim=xlim)
   axis(4)
  
   Cheers,
  
  
   Rainer
   --
   Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
  Biology,
   UCT), Dipl. Phys. (Germany)
  
   Centre of Excellence for Invasion Biology
   Natural Sciences Building
   Office Suite 2039
   Stellenbosch University
   Main Campus, Merriman Avenue
   Stellenbosch
   South Africa
  
   Cell:   +27 - (0)83 9479 042
   Fax:+27 - (0)86 516 2782
   Fax:+49 - (0)721 151 334 888
   email:  rai...@krugs.de
  
   Skype:  RMkrug
   Google: r.m.k...@gmail.com
  
  [[alternative HTML version deleted]]
  
   __
   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.
 
 
 
 
 -- 
 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation 
Biology,
 UCT), Dipl. Phys. (Germany)
 
 Centre of Excellence for Invasion Biology
 Natural Sciences Building
 Office Suite 2039
 Stellenbosch University
 Main Campus, Merriman Avenue
 Stellenbosch
 South Africa
 
 Cell:   +27 - (0)83 9479 042
 Fax:+27 - (0)86 516 2782
 Fax:+49 - (0)721 151 334 888
 email:  rai...@krugs.de
 
 Skype:  RMkrug
 Google: r.m.k...@gmail.com
 
[[alternative HTML version deleted]]
 
 __
 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] Second y-axis --- alternative to par(new=

2009-10-07 Thread Rainer M Krug
On Wed, Oct 7, 2009 at 11:53 AM, Petr PIKAL petr.pi...@precheza.cz wrote:

 r-help-boun...@r-project.org napsal dne 07.10.2009 11:37:22:

  On Wed, Oct 7, 2009 at 11:28 AM, Petr PIKAL petr.pi...@precheza.cz
 wrote:
 
   Hi
  
   Try ?twoord.plot from plotrix package.
  
  
  Thanks Petr - I was not aeware of this command.
  But I would prefer a more general solution. An example on where I am
 using
  is, to plot a histogram overlayed by its density estimate (easier to
 digest
  for others then only a density estimate).

 That is quite different from your example.


Well - in both cases, I want to overlay two graphs - in my example, it is a
line and a point plot, in the other a histogram and a density estimate.


 I believe overlay of density
 curve over histogram was discussed several times e.g.
 http://tolstoy.newcastle.edu.au/R/e4/help/08/06/14198.html

 Thanks - but if I want to have the histogram with counts (freq=TRUE), then
I have exactly the situation I was talking about - sorry for not being
clear:

x - rnorm(200)
hist(x, col = blue, freq = TRUE)
lines(density(x), col = red, lwd = 2)

i.e.
left y-axis (histogram): count
right y-axis (density estimate): probability density

 And a newY() (or par(newY=TRUE) command would enable exactly this.

 This is something beyond my knowledge and it could be that this need some
 deep redefining in base R graphics.


That's what I guess as well - let's see.

Rainer


 Regards
 Petr

 
  Regards,
 
  Rainer
 
 
 
   Regards
   Petr
  
  
  
   r-help-boun...@r-project.org napsal dne 07.10.2009 10:29:53:
  
Hi
   
is there an alternative to par(new), for ading data to a plot for a
different y-axis?
My problem with par(new=TRUE) is, that it re-defines all axis and
 labels
   (as
in example 1) and one has to use xlim=... to fix the x-axis.
I am looking for something, which simply resets the y-axis, so that
 a
   new
plot() (or points()/lines()) keeps the x-axis, but re-defines the
   y-axis.
   
Is there something available? I could re-scale the y-data to fit the
existing y-axis, but that would mean to define all the labels and
   tickmarks
for axis 4 manually.
   
HEre is an example about what I mean:
   
x1 - 1:10
y1 - runif(10)
x2 - 1:11
y2 - c(y1*100, 0)
   
## (1) Does not plot points where (x-axis) they should be
plot(x1, y1, type=l)
par(new=TRUE)
plot(x2, y2, type=p)
axis(4)
   
## (2) Does plot points where (x-axis) they should be
xlim - range(x1)
plot(x1, y1, type=l, xlim=xlim)
par(new=TRUE)
plot(x2, y2, type=p, xlim=xlim)
axis(4)
   
Cheers,
   
   
Rainer
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
   Biology,
UCT), Dipl. Phys. (Germany)
   
Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa
   
Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)721 151 334 888
email:  rai...@krugs.de
   
Skype:  RMkrug
Google: r.m.k...@gmail.com
   
   [[alternative HTML version deleted]]
   
__
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.
  
  
 
 
  --
  Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
 Biology,
  UCT), Dipl. Phys. (Germany)
 
  Centre of Excellence for Invasion Biology
  Natural Sciences Building
  Office Suite 2039
  Stellenbosch University
  Main Campus, Merriman Avenue
  Stellenbosch
  South Africa
 
  Cell:   +27 - (0)83 9479 042
  Fax:+27 - (0)86 516 2782
  Fax:+49 - (0)721 151 334 888
  email:  rai...@krugs.de
 
  Skype:  RMkrug
  Google: r.m.k...@gmail.com
 
 [[alternative HTML version deleted]]
 
  __
  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.




-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)721 151 334 888
email:  rai...@krugs.de

Skype:  RMkrug
Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]

__

Re: [R] Second y-axis --- alternative to par(new=

2009-10-07 Thread Petr PIKAL
Hi

Rainer M Krug r.m.k...@gmail.com napsal dne 07.10.2009 12:09:21:

 

 On Wed, Oct 7, 2009 at 11:53 AM, Petr PIKAL petr.pi...@precheza.cz 
wrote:
 r-help-boun...@r-project.org napsal dne 07.10.2009 11:37:22:
 
  On Wed, Oct 7, 2009 at 11:28 AM, Petr PIKAL petr.pi...@precheza.cz
 wrote:
 
   Hi
  
   Try ?twoord.plot from plotrix package.
  
  
  Thanks Petr - I was not aeware of this command.
  But I would prefer a more general solution. An example on where I am
 using
  is, to plot a histogram overlayed by its density estimate (easier to
 digest
  for others then only a density estimate).

 That is quite different from your example. 
 
 Well - in both cases, I want to overlay two graphs - in my example, it 
is a 
 line and a point plot, in the other a histogram and a density estimate.
  
 I believe overlay of density
 curve over histogram was discussed several times e.g.
 http://tolstoy.newcastle.edu.au/R/e4/help/08/06/14198.html
 
 Thanks - but if I want to have the histogram with counts (freq=TRUE), 
then I 
 have exactly the situation I was talking about - sorry for not being 
clear:
 
 x - rnorm(200) 
 hist(x, col = blue, freq = TRUE) 
 lines(density(x), col = red, lwd = 2) 
 
 i.e. 
 left y-axis (histogram): count
 right y-axis (density estimate): probability density

  And a newY() (or par(newY=TRUE) command would enable exactly this.

 This is something beyond my knowledge and it could be that this need 
some
 deep redefining in base R graphics.

 
 That's what I guess as well - let's see.


In the meantime, what about

x - rnorm(200) 
hist(x, col = blue, freq = TRUE) 
ddd-density(x)
lines(ddd$x, ddd$y*100, col = red, lwd = 2) 

and then add suitable y axis.

axis(4, at=pretty(ddd$y*100), labels=pretty(ddd$y), col=2)

Regards
Petr


 
 Rainer
  
 Regards
 Petr
 
 
  Regards,
 
  Rainer
 
 
 
   Regards
   Petr
  
  
  
   r-help-boun...@r-project.org napsal dne 07.10.2009 10:29:53:
  
Hi
   
is there an alternative to par(new), for ading data to a plot for 
a
different y-axis?
My problem with par(new=TRUE) is, that it re-defines all axis and
 labels
   (as
in example 1) and one has to use xlim=... to fix the x-axis.
I am looking for something, which simply resets the y-axis, so 
that
 a
   new
plot() (or points()/lines()) keeps the x-axis, but re-defines the
   y-axis.
   
Is there something available? I could re-scale the y-data to fit 
the
existing y-axis, but that would mean to define all the labels and
   tickmarks
for axis 4 manually.
   
HEre is an example about what I mean:
   
x1 - 1:10
y1 - runif(10)
x2 - 1:11
y2 - c(y1*100, 0)
   
## (1) Does not plot points where (x-axis) they should be
plot(x1, y1, type=l)
par(new=TRUE)
plot(x2, y2, type=p)
axis(4)
   
## (2) Does plot points where (x-axis) they should be
xlim - range(x1)
plot(x1, y1, type=l, xlim=xlim)
par(new=TRUE)
plot(x2, y2, type=p, xlim=xlim)
axis(4)
   
Cheers,
   
   
Rainer
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
   Biology,
UCT), Dipl. Phys. (Germany)
   
Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa
   
Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)721 151 334 888
email:  rai...@krugs.de
   
Skype:  RMkrug
Google: r.m.k...@gmail.com
   
   [[alternative HTML version deleted]]
   
__
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.
  
  
 
 
  --
  Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
 Biology,
  UCT), Dipl. Phys. (Germany)
 
  Centre of Excellence for Invasion Biology
  Natural Sciences Building
  Office Suite 2039
  Stellenbosch University
  Main Campus, Merriman Avenue
  Stellenbosch
  South Africa
 
  Cell:   +27 - (0)83 9479 042
  Fax:+27 - (0)86 516 2782
  Fax:+49 - (0)721 151 334 888
  email:  rai...@krugs.de
 
  Skype:  RMkrug
  Google: r.m.k...@gmail.com
 
 [[alternative HTML version deleted]]
 
  __
  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.

 
 
 
 -- 
 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation 
Biology, 
 UCT), Dipl. Phys. (Germany)
 
 Centre of Excellence for Invasion Biology
 Natural Sciences Building
 Office Suite 2039
 Stellenbosch 

Re: [R] Second y-axis --- alternative to par(new=

2009-10-07 Thread Rainer M Krug
On Wed, Oct 7, 2009 at 12:26 PM, Petr PIKAL petr.pi...@precheza.cz wrote:

 Hi

 Rainer M Krug r.m.k...@gmail.com napsal dne 07.10.2009 12:09:21:

 

  On Wed, Oct 7, 2009 at 11:53 AM, Petr PIKAL petr.pi...@precheza.cz
 wrote:
  r-help-boun...@r-project.org napsal dne 07.10.2009 11:37:22:
 
   On Wed, Oct 7, 2009 at 11:28 AM, Petr PIKAL petr.pi...@precheza.cz
  wrote:
  
Hi
   
Try ?twoord.plot from plotrix package.
   
   
   Thanks Petr - I was not aeware of this command.
   But I would prefer a more general solution. An example on where I am
  using
   is, to plot a histogram overlayed by its density estimate (easier to
  digest
   for others then only a density estimate).

  That is quite different from your example.
 
  Well - in both cases, I want to overlay two graphs - in my example, it
 is a
  line and a point plot, in the other a histogram and a density estimate.
 
  I believe overlay of density
  curve over histogram was discussed several times e.g.
  http://tolstoy.newcastle.edu.au/R/e4/help/08/06/14198.html
 
  Thanks - but if I want to have the histogram with counts (freq=TRUE),
 then I
  have exactly the situation I was talking about - sorry for not being
 clear:
 
  x - rnorm(200)
  hist(x, col = blue, freq = TRUE)
  lines(density(x), col = red, lwd = 2)
 
  i.e.
  left y-axis (histogram): count
  right y-axis (density estimate): probability density

   And a newY() (or par(newY=TRUE) command would enable exactly this.

  This is something beyond my knowledge and it could be that this need
 some
  deep redefining in base R graphics.

 
  That's what I guess as well - let's see.


 In the meantime, what about

 x - rnorm(200)
 hist(x, col = blue, freq = TRUE)
 ddd-density(x)
 lines(ddd$x, ddd$y*100, col = red, lwd = 2)

 and then add suitable y axis.

 axis(4, at=pretty(ddd$y*100), labels=pretty(ddd$y), col=2)


Yes - that definitely works.

I usually use the following approach: determine the xlims in advance, and
then set them manually for each plot:

x - rnorm(200)
xlim - trunc(range(x)) + c(-1, +1)

hist(x, col = blue, freq = TRUE, xlim=xlim)
par(new=TRUE)
plot(density(x), xlim=xlim, ann=FALSE, axes=FALSE)
axis(4)

But it is sometimes tricky to get the xlims for the plot.


 Regards
 Petr


 
  Rainer
 
  Regards
  Petr
 
  
   Regards,
  
   Rainer
  
  
  
Regards
Petr
   
   
   
r-help-boun...@r-project.org napsal dne 07.10.2009 10:29:53:
   
 Hi

 is there an alternative to par(new), for ading data to a plot for
 a
 different y-axis?
 My problem with par(new=TRUE) is, that it re-defines all axis and
  labels
(as
 in example 1) and one has to use xlim=... to fix the x-axis.
 I am looking for something, which simply resets the y-axis, so
 that
  a
new
 plot() (or points()/lines()) keeps the x-axis, but re-defines the
y-axis.

 Is there something available? I could re-scale the y-data to fit
 the
 existing y-axis, but that would mean to define all the labels and
tickmarks
 for axis 4 manually.

 HEre is an example about what I mean:

 x1 - 1:10
 y1 - runif(10)
 x2 - 1:11
 y2 - c(y1*100, 0)

 ## (1) Does not plot points where (x-axis) they should be
 plot(x1, y1, type=l)
 par(new=TRUE)
 plot(x2, y2, type=p)
 axis(4)

 ## (2) Does plot points where (x-axis) they should be
 xlim - range(x1)
 plot(x1, y1, type=l, xlim=xlim)
 par(new=TRUE)
 plot(x2, y2, type=p, xlim=xlim)
 axis(4)

 Cheers,


 Rainer
 --
 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology,
 UCT), Dipl. Phys. (Germany)

 Centre of Excellence for Invasion Biology
 Natural Sciences Building
 Office Suite 2039
 Stellenbosch University
 Main Campus, Merriman Avenue
 Stellenbosch
 South Africa

 Cell:   +27 - (0)83 9479 042
 Fax:+27 - (0)86 516 2782
 Fax:+49 - (0)721 151 334 888
 email:  rai...@krugs.de

 Skype:  RMkrug
 Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]

 __
 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.
   
   
  
  
   --
   Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
  Biology,
   UCT), Dipl. Phys. (Germany)
  
   Centre of Excellence for Invasion Biology
   Natural Sciences Building
   Office Suite 2039
   Stellenbosch University
   Main Campus, Merriman Avenue
   Stellenbosch
   South Africa
  
   Cell:   +27 - (0)83 9479 042
   Fax:+27 - (0)86 516 2782
   Fax:+49 - (0)721 151 334 888
   email:  rai...@krugs.de
  
   Skype:  

Re: [R] Second y-axis --- alternative to par(new=

2009-10-07 Thread Petr PIKAL
Hi

Rainer M Krug r.m.k...@gmail.com napsal dne 07.10.2009 12:40:39:

 

 On Wed, Oct 7, 2009 at 12:26 PM, Petr PIKAL petr.pi...@precheza.cz 
wrote:
 Hi
 
 Rainer M Krug r.m.k...@gmail.com napsal dne 07.10.2009 12:09:21:
 
 
 

snip

 In the meantime, what about
 
 x - rnorm(200)
 hist(x, col = blue, freq = TRUE)
 ddd-density(x)
 lines(ddd$x, ddd$y*100, col = red, lwd = 2)
 
 and then add suitable y axis.
 
 axis(4, at=pretty(ddd$y*100), labels=pretty(ddd$y), col=2)
 
 Yes - that definitely works.
 
 I usually use the following approach: determine the xlims in advance, 
and then
 set them manually for each plot:
 
 x - rnorm(200)
 xlim - trunc(range(x)) + c(-1, +1)
 
 hist(x, col = blue, freq = TRUE, xlim=xlim)

hhh - hist(x, col = blue, freq = TRUE)

gives you object from which you can extract limits for plotting maybe 
better then from original data and you do not need to call

 par(new=TRUE)

Regards
Petr

 plot(density(x), xlim=xlim, ann=FALSE, axes=FALSE)
 axis(4)
  
 But it is sometimes tricky to get the xlims for the plot.
 
 Regards
 Petr


__
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] Second y-axis --- alternative to par(new=

2009-10-07 Thread Rainer M Krug
On Wed, Oct 7, 2009 at 1:48 PM, Petr PIKAL petr.pi...@precheza.cz wrote:

 Hi

 Rainer M Krug r.m.k...@gmail.com napsal dne 07.10.2009 12:40:39:

 

  On Wed, Oct 7, 2009 at 12:26 PM, Petr PIKAL petr.pi...@precheza.cz
 wrote:
  Hi
 
  Rainer M Krug r.m.k...@gmail.com napsal dne 07.10.2009 12:09:21:
 
  
 

 snip

  In the meantime, what about
 
  x - rnorm(200)
  hist(x, col = blue, freq = TRUE)
  ddd-density(x)
  lines(ddd$x, ddd$y*100, col = red, lwd = 2)
 
  and then add suitable y axis.
 
  axis(4, at=pretty(ddd$y*100), labels=pretty(ddd$y), col=2)
 
  Yes - that definitely works.
 
  I usually use the following approach: determine the xlims in advance,
 and then
  set them manually for each plot:
 
  x - rnorm(200)
  xlim - trunc(range(x)) + c(-1, +1)
 
  hist(x, col = blue, freq = TRUE, xlim=xlim)

 hhh - hist(x, col = blue, freq = TRUE)

 gives you object from which you can extract limits for plotting maybe
 better then from original data and you do not need to call

  par(new=TRUE)

 True.

Thanks a lot,

Rainer


 Regards
 Petr

  plot(density(x), xlim=xlim, ann=FALSE, axes=FALSE)
  axis(4)
 
  But it is sometimes tricky to get the xlims for the plot.
 
  Regards
  Petr
 




-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)721 151 334 888
email:  rai...@krugs.de

Skype:  RMkrug
Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]

__
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] Second y-axis --- alternative to par(new=

2009-10-07 Thread cls59



Rainer M Krug-6 wrote:
 
 Thanks - but if I want to have the histogram with counts (freq=TRUE), then
 I have exactly the situation I was talking about - sorry for not being
 clear:
 
 x - rnorm(200)
 hist(x, col = blue, freq = TRUE)
 lines(density(x), col = red, lwd = 2)
 
 i.e.
 left y-axis (histogram): count
 right y-axis (density estimate): probability density
 
 

When adding a second y-axis, I always rescale the plot with a call to
plot.window() rather than par(new=T). This rescales the plotting area while
still allowing low-level plotting functions like lines and points to be
executed:

x - rnorm(200)
hist(x, col = blue, freq = TRUE)

# recovering par('xaxp') uses the original x limits.
plot.window( xlim = range( par('xaxp')[1:2] ), ylim = range( density(x)$y ))

lines(density(x), col = red, lwd = 2)

Hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Second-y-axis-alternative-to-par%28new%3D-tp25782532p25787630.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Second y-axis --- alternative to par(new=

2009-10-07 Thread cls59


cls59 wrote:
 
 
 # recovering par('xaxp') uses the original x limits.
 plot.window( xlim = range( par('xaxp')[1:2] ), ylim = range( density(x)$y
 )) 
 
 

Actually, I misspoke. I believe the following is the voodoo you want for
exactly recovering the original xlimit:


  plot.window( xlim = range( par('usr')[1:2] ), xaxs = 'i', ylim = range(
density(x)$y )) 


Basically, par('xaxp')[1:2] only returns the extreme values of the tick
marks on the original x-axis-- using these can still cause points not to
line up. par('usr')[1:2] returns the coordinates of the left and right edges
of the plot screen. setting xaxs to 'i' causes R to use the xlimit exactly
as given and not to pad it by 4% in an attempt to make it pretty.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Second-y-axis-alternative-to-par%28new%3D-tp25782532p25787984.html
Sent from the R help mailing list archive at Nabble.com.

__
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] second y-axis in lattice xyplot

2009-08-18 Thread Kara Przeczek
Dear R-help,
I recently discovered lattice xyplot, but have been struggling with plotting a 
second y-axis. I am able to do this with plot() but can't figure it out in 
xyplot. Any help would be appreciated.
I have found help on adding a second Y-axis when the data is all part of the 
same data frame, but I have two different data frames.
Both data sets are being plotted against Date. However the first data set 
only plots a few points on select dates whereas the second data set is plotted 
daily. I would like to plot them both with the same x-axis, but separate 
(labeled) y-axes. Is this possibly in lattice xyplot without too much hassle? 
Or am I better off plotting with plot()?

#The first data set plot:
trellis.par.set(superpose.symbol = list(cex = 1.3, pch = c(15,0,17,2), 
col=c(blue,blue,red,red)) )

xyplot(melt ~ Date, data = df1, groups = si, col = c(blue,blue,red,red),
   pch= c(15,0,17,2), type = 'p',
   auto.key = list(points = TRUE, lines = FALSE, x=0.8, y=0.15, corner = 
c(0,1))
  )

#The second data set plot:
xyplot(AT ~ Date, data = df2,
  type = 'o', lty = 1, col = black
   )

Example data:
#df1:
Date - as.Date(rep(c(2008-04-27,2008-05-02),each=4), format=%Y-%m-%d)
si - factor(rep(c(SO,SF,NO,NF),2))
melt - c(4.7,7.4,17.8,30.8,2.2,11.7,10.1,17.3)
df1 - data.frame(Date, si, melt)

#df2:
Date - 
as.Date(c(2008-04-27,2008-04-28,2008-04-29,2008-04-30,2008-05-01,2008-05-02),
 format=%Y-%m-%d)
AT - c(7.4,4.5,3.2,2.1,2.0,1.1)
df2 - data.frame(Date,AT)

Thank you very much for your time.
Kara

__
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] second y-axis in lattice xyplot

2009-08-18 Thread Duncan Mackay

At 07:50 19/08/2009, you wrote:

Dear R-help,
I recently discovered lattice xyplot, but have been struggling with 
plotting a second y-axis. I am able to do this with plot() but can't 
figure it out in xyplot. Any help would be appreciated.
I have found help on adding a second Y-axis when the data is all part of 
the same data frame, but I have two different data frames.
Both data sets are being plotted against Date. However the first data 
set only plots a few points on select dates whereas the second data set is 
plotted daily. I would like to plot them both with the same x-axis, but 
separate (labeled) y-axes. Is this possibly in lattice xyplot without too 
much hassle? Or am I better off plotting with plot()?


#The first data set plot:
trellis.par.set(superpose.symbol = list(cex = 1.3, pch = c(15,0,17,2), 
col=c(blue,blue,red,red)) )


xyplot(melt ~ Date, data = df1, groups = si, col = 
c(blue,blue,red,red),

   pch= c(15,0,17,2), type = 'p',
   auto.key = list(points = TRUE, lines = FALSE, x=0.8, y=0.15, 
corner = c(0,1))

  )

#The second data set plot:
xyplot(AT ~ Date, data = df2,
  type = 'o', lty = 1, col = black
   )

Example data:
#df1:
Date - as.Date(rep(c(2008-04-27,2008-05-02),each=4), format=%Y-%m-%d)
si - factor(rep(c(SO,SF,NO,NF),2))
melt - c(4.7,7.4,17.8,30.8,2.2,11.7,10.1,17.3)
df1 - data.frame(Date, si, melt)

#df2:
Date - 
as.Date(c(2008-04-27,2008-04-28,2008-04-29,2008-04-30,2008-05-01,2008-05-02), 
format=%Y-%m-%d)

AT - c(7.4,4.5,3.2,2.1,2.0,1.1)
df2 - data.frame(Date,AT)

Thank you very much for your time.
Kara

__
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.


Hi Kara

just a quick fix. you will have to look at ?doubleYScale to improve things

 require(latticeExtra)
 xyplot(melt ~ Date, data = df1, groups = si, col = 
c(blue,blue,red,red),

+pch= c(15,0,17,2), type = 'p',
+auto.key = list(points = TRUE, lines = FALSE, x=0.8, y=0.15, 
corner = c(0,1))

+   )
+
+ ,xyplot(AT ~ Date, data = df2,
+   type = 'o', lty = 1, col = black
+)
)

HTH

Duncan Mackay
Department of Agronomy and Soil Science
Univeristy of New England
ARMIDALE NSW 2351
Email: home : mac...@northnet.com.au

__
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] Second y-axis

2008-11-26 Thread Dr. Alireza Zolfaghari
Hi list,
In the following code, how can I place the percentage label away from
numbers in the second y-axis (lets say all should be inside plot area)?

Thanks
Alireza

=
require(grid)
vp- viewport(x=.1,y=.1,width=.6,height=.6,just=c(left, bottom))
pushViewport(vp)
plotDATA=data.frame(Loss=c(1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10),Level=c(AvgAll,AvgAll,AvgAll,AvgAll,AvgAll,AvgAll,AvgAll,
AvgAll,AvgAll,AvgAll,AvgAll,AvgAll,GUL,GUL,GUL,GUL,GUL,GUL,GUL,GUL),Line=c(1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8))
library(lattice)
xyplot( Loss ~ Line, data=plotDATA, t=p,
scales=list(relation=free, x=list(draw=TRUE, tick.number=12, labels=
1:12)),par.settings = list(clip = list(panel = off)))
p- xyplot( Loss ~ Line, data=plotDATA,
t=p,scales=list(relation=free,x=list(at = 1:12)),
panel=function(x,y,subscripts, groups,...){
panel.xyplot(subset(plotDATA, Level==AvgAll)$Line,subset(plotDATA,
Level==AvgAll)$Loss ,col=Lloydscolour(colIncP),lwd=3,origin=0,...)
panel.axis(side = right,
at=unique(plotDATA$Loss),labels=unique(plotDATA$Loss)/max(plotDATA$Loss)*100,outside=FALSE,ticks=TRUE,half=FALSE)
panel.axis(side = right,
at=median(plotDATA$Loss),labels=Percentage,outside=FALSE,ticks=FALSE,half=FALSE,rot=90)
panel.axis(side = right,
at=c(4,8),labels=c(200,400),outside=TRUE,ticks=TRUE,half=FALSE)
panel.barchart(subset(plotDATA,Level==GUL )$Line,
subset(plotDATA,Level==GUL )$Loss,box.ratio=1,horizontal = FALSE,stack =
TRUE,reference = TRUE,col=blue,border=blue)#,origin=0)
 }
 )

 print(p,position = c(0.1, 0.1, 0.9, .9))
=

[[alternative HTML version deleted]]

__
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.