[R] Odp: Second y-axis --- alternative to par(new=
Petr PIKAL
petr.pikal at precheza.cz
Wed Oct 7 11:28:12 CEST 2009
Hi
Try ?twoord.plot from plotrix package.
Regards
Petr
r-help-bounces at 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: Rainer at krugs.de
>
> Skype: RMkrug
> Google: R.M.Krug at gmail.com
>
> [[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.
More information about the R-help
mailing list