[R] Using latticeExtra as.layer function with different number of plot panels
David Winsemius
dwinsemius at comcast.net
Thu Jul 30 21:51:53 CEST 2015
On Jul 30, 2015, at 8:37 AM, sbihorel wrote:
> 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
I don't know if this works using the `+.lattice` function but it is possible to selectively update panels using `trellis.focus`
--
David.
>
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list