[R] setting key boxes in xyplot

David Winsemius dwinsemius at comcast.net
Fri May 1 15:28:48 CEST 2009


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)
>
>
> Because the plot actually plots, there is no error message reported.  
> I'm
> interested in getting the call statement to work as intended.

I see no call statement.
>
>
> Again, my apologies for being unclear in my first posting,  this  
> list is a
> great resources and I learn from everyone daily.
>
> Thanks
> Steve
> On Apr 30, 2009, at 10:35 AM, Steve_Friedman at nps.gov wrote:
>>
>> I thought I mimicked the coded correctly, but find an error/omission
>> somewhere in the xyplot function shown below.
>>
>>> eggs # alligator egg fate
>>
>> dput(round(eggs, 2), file = "")
>> structure(list(Year = c(1985, 1986, 1987, 1988, 1989, 1990, 1991,
>> 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000), NumEggs =
>> c(323,
>> 1729, 1127, 104, 267, 291, 352, 478, 532, 569, 263, 490, 244,
>> 428, 527, 670), Failed = c(183, 199, 257, 503, 99, 139, 273,
>> NA, 0, 55, 237, 581, 271, 144, 117, 43), Mean = c(0.29, 0.49,
>> 0.55, 0.45, 0.26, 0.34, 0, 0.49, 0.77, 0.57, 0.77, NA, 0.69,
>> 0.64, 0.51, 0.66), Eggs.p = c(0.19, 1, 0.65, 0.06, 0.15, 0.17,
>> 0.2, 0.28, 0.31, 0.33, 0.15, 0.28, 0.14, 0.25, 0.3, 0.39), Fail.p =
>> c(0.31,
>> 0.34, 0.44, 0.87, 0.17, 0.24, 0.47, NA, 0, 0.09, 0.41, 1, 0.47,
>> 0.25, 0.2, 0.07)), .Names = c("Year", "NumEggs", "Failed", "Mean",
>> "Eggs.p", "Fail.p"), row.names = c("1985", "1986", "1987", "1988",
>> "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996",
>> "1997", "1998", "1999", "2000"), class = "data.frame")
>>
>>
>> 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),  type = c("b", "b", "h"),
>>        key = list(text = list(c("Proportion Hatched R^2 = 0.13,
>> Proportion Flooded R^2 = -0.23, Mean HSI")),
>>        col = c("black","red", "green")), columns = 3)
>
> It runs without error on my machine ... after loading lattice. Perhaps
> you ought to provide the error message .... and the other usual needed
> information. See that nice compact but very imformative message at the
> bottom of this reply.
>
> --
> David
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>
>

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list