[R] lattice fun: multiple themes in panels with spplot()

nbest937 nbest at ci.uchicago.edu
Wed Dec 15 00:42:03 CET 2010


I have some geospatial data where two layers are thematic and the third is a
percentage, so the maps need to have different themes.  

thumbDf <- as( stack( thumb), "SpatialGridDataFrame")
names(thumbDf at data) <- c("pri", "sec", "pct")
thumbDf at data$pri <- factor(thumbDf at data$pri, levels=c(0:8), labels= names(
peelClasses))
thumbDf at data$sec <- factor(thumbDf at data$sec, levels=c(0:8), labels= names(
peelClasses))

stack() comes from library(raster), which does not do lattice natively and
doesn't plot thematic maps particularly well, AFAIK.  Coercing the data to
something that spplot() can handle and changing the thematic data to factors
results in a very satisfactory legend for that theme.  I would like the
third map to have the same size so that they more closely resemble a set of
panels even though they have different themes.

I have experimented with three approaches:


thumbDfPlot <- 
  spplot(thumbDf, c("pri", "sec"), 
         names.attr=c("Primary cover", "Secondary cover"), 
         between= list( x=0.5))


trellis.par.set( peelTheme)
plot( thumbDfPlot, split= c(1,1,2,1), more=TRUE)
trellis.par.set(sp.theme())
plot( spplot(thumbDf, "pct"), split= c(2,1,2,1))

The second plot (showing the "third" panel) is taller because it's legend is
narrower and together they have half of the page to work with.  Also, it
does not have a panel title showing it's name ("pct" unless I give it
something else, which I cannot figure out how to do for a plot of one panel.

trellis.par.set( peelTheme)
plot( spplot( thumbDf, "pri"), split= c(1,1,3,1), more=TRUE)
plot( spplot( thumbDf, "sec"), split= c(2,1,3,1), more=TRUE)
trellis.par.set(sp.theme())
plot( spplot(thumbDf, "pct"), split= c(3,1,3,1), position= c(0,0.25,1,0.75))

Doing it this way, each of the first two gets its own legend, which is not
what I want either, but at least none of them has a panel title, so I could
give them each a plot title.  The size is close, but not quite right.  I
could probably get it pretty close changing the position vector itertively,
but that is not very satisfying.

trellis.par.set( peelTheme)
plot( thumbDfPlot, position= c(0,0,0.625,1), more=TRUE)
trellis.par.set(sp.theme())
plot( spplot(thumbDf, "pct", names.attr="Confidence"), position=c(
0.625,0,1,1))

Sizing is closer than the first, but the same basic issues are still in
play, plus names.attr has no effect.  There must be a way to link the panel
sizes from one plot to the next in case something else changes.

Is there a way to turn off the legend and plot it separately, extracting it
from the original spplot() object?

Is it possible to specify the theme panel by panel?

I could post some images somewhere if it's helpful.  Any suggestions on a
free, public tool for doing that?

Thanks for taking a look at this.


Climbing the lattice learning curve,

Neil

-- 
View this message in context: http://r.789695.n4.nabble.com/lattice-fun-multiple-themes-in-panels-with-spplot-tp3088225p3088225.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list