[R] setting key boxes in xyplot

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed May 6 23:57:51 CEST 2009


On Fri, May 1, 2009 at 6:28 AM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On May 1, 2009, at 8:51 AM, Steve_Friedman at nps.gov wrote:
>
>> David and the list
>>
>> Yes the graph is produced with the code I submitted. However, I was not
>> clear in my initial post. and it is totally my mistake for taking up
>> everyone's valuable time.
>>
>> My main question focuses on the key which prints in black as opposed to
>> using the colors ("black", "red" and "green").  The second question
>> pertains to the use of superscripts.  I'd like the R^2 values to actually
>> use a exponent.
>
> This gives you at least part of what I imagine you may want:
>
> xyplot(Eggs.p + Fail.p + Mean ~ Year , data = eggs, cex = 0.8, pch = c(2,
> 5),
>       panel = panel.superpose.2, main = "Alligator Nest Fate",
>       ylab = "Prop. of Total Number of Hatched Eggs \n Prop. of
> Total
> Flooded Eggs",
>       legend = list(right = list(fun = grid::textGrob("Mean HSI",
>                                rot=90))), col=(1:3),
> # I have not figured out what that legend is supposed to be doing.
>
>        type = c("b", "b", "h"),
>
> # I find that plotting with the "h" options obscures the meaning.
> # But it's your plot.
>
>       key = list(text = list(c(
>                expression("Proportion Hatched "~R^2~" = 0.13"),
>                expression("Proportion Flooded "~R^2~" = -0.23"),
>                expression("Mean HSI"))),
>       col = c("black","red", "green")), columns = 3)

And a minor modification, in case the intention was to associate the
colors with lines:



xyplot(Eggs.p + Fail.p + Mean ~ Year , data = eggs, cex = 0.8, pch = c(2, 5),
       panel = panel.superpose.2, main = "Alligator Nest Fate",
       ylab = "Prop. of Total Number of Hatched Eggs \n Prop. of Total
Flooded Eggs",
       legend = list(right = list(fun = grid::textGrob("Mean HSI", rot=90))),
       type = c("b", "b", "h"),
       col = c("black","red", "green"),
       key =
       list(text = list(expression("Proportion Hatched "~R^2~" = 0.13",
                                   "Proportion Flooded "~R^2~" = -0.23",
                                   "Mean HSI")),
            lines = list(col = c("black","red", "green")),
            columns = 1))

-Deepayan




More information about the R-help mailing list