[R] label of second y-axis in xyplot (lattice)
Deepayan Sarkar
deepayan.sarkar at gmail.com
Tue Jan 17 23:30:18 CET 2006
On 1/16/06, Antje Schüle <Antje.Schuele at komdat.com> wrote:
> Dear group,
>
>
>
> First I provide you with an example, I found in the newsgroup. Then I'd like
> to explain my problem to you by means of the output.
>
>
>
> enviro <-
> data.frame(Year = rep(2001:2002, each = 365),
> Day = rep(1:365, 2),
> Precip = pmax(0, rnorm(365 * 2)),
> Temp = 2 + 0.2 * rnorm(365 * 2))
>
>
> xyplot(Precip + Temp ~ Day | Year, data=enviro,
> layout = c(1, 2),
> panel = panel.superpose.2,
> type = c('h', 'l'))
>
>
>
> Now my question.
>
>
>
> How can I achieve different labels for two y-axes? (Here this is not the
> case, but the example should just visualize my question.)
>
> So here in this case I'd like to have two labels. On the "normal" y-side
> (axis2) the label = "Precip", on the other side (axis4) the label "Temp".
The design of xyplot etc doesn't permit this. One (fake) solution is
to add a legend:
xyplot(Precip + Temp ~ Day | Year, data=enviro,
layout = c(1, 2),
panel = panel.superpose.2,
ylab = "Precip",
legend = list(right =
list(fun = grid::textGrob("Temp", rot = 90))),
type = c('h', 'l'))
Deepayan
--
http://www.stat.wisc.edu/~deepayan/
More information about the R-help
mailing list