Question on ssplot key
On 25 June 2010 04:15, Kenneth Takagi <katakagi at bu.edu> wrote:
Hi All, I have a question about producing keys in ssplot(). ?I've included reproducible code below. Here goes: I'd like to produce a key in ssplot that has both rectangles, points and lines. ?Unfortunately, when you include all of these symbols in one key, the produce a "staggered" look with rectangles on the far left and lines closest to the labels (run script below to see what I am talking about). Questions: 1. How can you have them all line up in a single column? I tried using negative values for "size" of rectangles, but that begins to change the size of the grey background box. 2. ?key.space does not seem to change anything when used inside the update function. Any suggestions on how to move the key?
update(plot1, key = list(
background = "grey90",
lines = list(type = c("l", rep("p", 6)),
pch = c(NA, 1:2, rep(22, 4)), ## 22 is filled square
fill = c(rep(NA, 3), rep("magenta", 4)),
border = "black"),
text = list(rep("Some Variable", 7)),
x = 0.1, y = 0.93, corner = c(1,0)
))
Thanks!
-Ken
# Reproducible Script:
library(sp)
library(lattice) # required for trellis.par.set():
trellis.par.set(sp.theme()) # sets color ramp to bpy.colors()
data(meuse)
coordinates(meuse)=~x+y
data(meuse.riv)
meuse.sr =
SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)),"meuse.riv")))
# Create spplot
plot1 = spplot(meuse, "zinc", auto.key=F, panel = function(x, y, ...) {
? ? ? ? ? ? ? ?sp.polygons(meuse.sr, fill = "lightblue")
? ? ? ? ? ? ? ?panel.pointsplot(x, y, auto.key = F, ...)
? ? ? ?},
? ? ? ?main = "Top soil zinc concentration (ppm)"
? ? ? ?)
#Update spplot
plot.update <- update(plot1,
key = list(rep = F, ?between.row = 0.75, between = 0.8, background="grey90",
key.space = list(x = 0.1, y = 0.93, corner = c(1,0)),
rectangle = list(col = c(rep(NA, 3), rep("magenta", 4)),
? ? ? ? ? ? ? ? border = c(rep(NA, 3),rep("black", 4)),
? ? ? ? ? ? ? ? size = 1.8, lwd = 7),
points = list(pch = c(NA, seq(1, 2,1), rep(NA, 4)),
? ? ? ? ? ? ?col = c(NA, rep("black", 2), rep(NA, 4))),
lines = list(type = "l", size = 2, lwd = 2, lty = 1),
text = list(rep("Some Variable", 7))
))
#Print spplot
print(plot.update)
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-- Felix Andrews / ??? Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 4670 E: felix.andrews at anu.edu.au CRICOS Provider No. 00120C