[R] Using latticeExtra as.layer function with different number of plot panels
sbihorel
Sebastien.Bihorel at cognigencorp.com
Thu Jul 30 17:37:55 CEST 2015
Hi,
When the as.layer function is used to overaly 2 lattice plots, there
seems to be an assumption that the data used in both plots will generate
the same number of panels (and, I believe, in the same order). In case
the data used in the plot within the as.layer call is incomplete , data
may be plotted on the "wrong" panel, and data seem to get re-used on the
last panel(s). See what happens in the example code below when the
records with state.region=="South" are dropped...
Is there a trick to overlay panel based upon the conditioning variable
value rather than the panel order?
require(lattice)
require(latticeExtra)
state2 <- state <- data.frame(state.x77,state.region)
state2$Income <- sample(state2$Income)
state3 <- state2[which(state2$state.region!="South"),]
foo <- xyplot(Income~Population|state.region,data=state,main='foo')
foo
bar <- update(foo,main='bar') +
as.layer(xyplot(Income~Population|state.region,data=state2,col='red'))
bar
bar2 <- update(foo,main='bar2') +
as.layer(xyplot(Income~Population|state.region,data=state3,col='red'))
bar2
Thank you
Sebastien
PS: I know that I could get what I want by setting the Income variable
to NA for records with state.region=="South" instead of dropping them...
but this is not the point of my example. I am just trying to illustrate
what happens when as.layer is used for plotting data with inconsistent
dimensions.
More information about the R-help
mailing list