[R] Accessor functions in lattice graphics
David Winsemius
dwinsemius at comcast.net
Mon Jun 20 16:17:21 CEST 2011
Frank Harrell wrote:
>
> I know about the current.row, current.column, and panel.number functions
> that are useful within panel functions written for lattice. Are there
> easy ways to obtain the names of the conditioning variables (those
> appearing after |) and their values for the current panel?
> Thanks
> Frank
>
Using one of the examples in help(xyplot):
states <- data.frame(state.x77,
state.name = dimnames(state.x77)[[1]],
state.region = state.region)
testp <- xyplot(Murder ~ Population | state.region, data = states,
groups = state.name,
panel = function(x, y, subscripts, groups) {
ltext(x = x, y = y, labels = groups[subscripts], cex=1,
fontfamily = "HersheySans")
})
str(testp)
I see that the names of the state.regions are in an attribute of
testp$packet.sizes, so:
> attr(testp$packet.sizes, "dimnames")[["state.region"]][4]
#[1] "West"
#Looking for a further example in help(xyplot with 2 "panel dimensions" I
tried:
> testp2 <- dotplot(variety ~ yield | year * site, data=barley)
#I'm not quite sure how the "rows" and "columns" are defined , but I get:
> attr(testp2$packet.sizes, "dimnames")[[1]][2]
[1] "1931"
> attr(testp2$packet.sizes, "dimnames")[[2]][1]
[1] "Grand Rapids"
I'm not sure this is the "right answer" because after looking further, I now
see a list node entitled $condlevels which returns the same information is a
much more straightforward fashion:
> testp2 $ condlevels
$year
[1] "1932" "1931"
$site
[1] "Grand Rapids" "Duluth" "University Farm" "Morris"
[5] "Crookston" "Waseca"
(And other nodes that contain information about conditioning levels:
$ index.cond :List of 2
..$ : int [1:2] 1 2
..$ : int [1:6] 1 2 3 4 5 6
$ perm.cond : int [1:2] 1 2
$ condlevels :List of 2
..$ year: chr [1:2] "1932" "1931"
..$ site: chr [1:6] "Grand Rapids" "Duluth" "University Farm" "Morris" ...
HTH;
David.
--
View this message in context: http://r.789695.n4.nabble.com/Accessor-functions-in-lattice-graphics-tp3609435p3611509.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list