[R] Second y-axis --- alternative to par(new=
Petr PIKAL
petr.pikal at precheza.cz
Wed Oct 7 13:48:34 CEST 2009
Hi
Rainer M Krug <r.m.krug at gmail.com> napsal dne 07.10.2009 12:40:39:
>
> On Wed, Oct 7, 2009 at 12:26 PM, Petr PIKAL <petr.pikal at precheza.cz>
wrote:
> Hi
>
> Rainer M Krug <r.m.krug at 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
>
More information about the R-help
mailing list