[R] Using latticeExtra as.layer function with different number of plot panels

Duncan Mackay dulcalma at bigpond.com
Fri Jul 31 05:53:16 CEST 2015


David has replied

But I am wondering if the lattice function make.groups is what you  want.
As you seem to want extra panels.
For the 3 graphs I get the 4 same panels NC W NE S and coloured points are
added after foo but bar2 has more red points added
bar1 and bar2 have the same colour for pch

I'm not upto date with some of the latticeExtra functions so cannot really
comment otherwise.

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
  
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of sbihorel
Sent: Friday, 31 July 2015 01:38
To: r-help at r-project.org
Subject: [R] Using latticeExtra as.layer function with different number of
plot panels

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.

______________________________________________
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.



More information about the R-help mailing list