[R-sig-Geo] spplot: 1) filling background polygon without overwriting foreground polygon; 2) left justifying sp.layout text

Lyndon Estes lestes at princeton.edu
Fri Oct 8 17:14:58 CEST 2010


Dear Edzer,

Very many thanks for the rapid response.  What you posted is exactly
what I was hoping for!

I will download the updated sp package and reproduce my maps.  Thanks again!

Best, Lyndon

On Fri, Oct 8, 2010 at 10:51 AM, Edzer Pebesma
<edzer.pebesma at uni-muenster.de> wrote:
> Thanks for the reproducable example. I can see what you want, and even
> with the intended syntax, i.e.
>
> sa.lst = list("sp.polygons", sa.shp, fill = "grey", first = T, col =
> "black")
>
> you don't get what I think you'd like. If the image attached is what you
> want, I committed a code change to the sp repository. I want to run some
> more checks to see whether it does not badly affect something else.
>
> Best regards,
>
> On 10/08/2010 04:18 PM, Lyndon Estes wrote:
>> Greetings,
>>
>> I have two questions related to spplot:
>>
>> 1. I am trying to plot one SpatialPolygonsDataFrame over another, and
>> fill the background polygon with grey. I can't seem to fill the
>> background polygon without having it cover over my supposed foreground
>> polygon, even if I specify "first = T" (which fails to draw the
>> background polygon):
>>
>> # Code
>>
>> # Load shapefiles
>> con1 <- url("http://sites.google.com/site/ldemisc/spplot-question/demo.mdshp.RData")
>> con2 <- url("http://sites.google.com/site/ldemisc/spplot-question/demo.sashp.RData")
>> load(con1); load(con2); close(con1); close(con2)
>>
>> # Set up plot background shape and additional text for map
>>
>> # Covers over md.shp
>> #sa.lst = list("sp.polygons", sa.shp, fill = "grey", col = "black")
>>
>> # Covers over md.shp
>> #sa.lst = list("sp.polygons", sa.shp, fill = "grey", first = F, col =
>> "black")
>>
>> # sa.shp doesn't plot
>> #sa.lst = list("sp.polygons", sa.shp, fill = "grey", first = T, col = "black")
>>
>> # Background polygon works like this, but without fill
>> sa.lst = list("sp.polygons", sa.shp, col = "black")
>>
>> # Additional text - overall mean yield.
>> text1 <- list("sp.text", c(360000, -3210000),
>>              paste("Overall mean yield =",
>> round(mean(md.shp at data[-c(22,69), 4]), 0), "kg/ha"),
>>              col ="red", cex = 1)
>>
>> # Scale bar limits and title
>> scmax  <- round(max(md.shp at data[, 4]) / 50, 0) * 50
>> scmin  <- round(min(md.shp at data[, 4]) / 50, 0) * 50
>> byval  <- 25
>> titlevec <- "Mean district maize yields (kg/ha) 1981-99: Cultivar PAN6528"
>>
>> # Spplot
>> dev.new()
>> spplot(md.shp[-c(22,69),], z = 4,
>>        sp.layout = list(sa.lst, text1),
>>        col.regions = topo.colors(500),
>>        at = seq(scmin, scmax, by = byval),
>>        main = titlevec)
>>
>> Any advice on how to correctly set "sa.lst" so that sa.shp fills
>> underneath md.shp will be much appreciated.  I haven't been able to
>> find a ready answer in the help files, except for this:
>>
>> "The order of items in sp.layout matters; objects are drawn in the
>> order they appear. Plot order and prevalence of sp.layout items: for
>> points and lines, sp.layout items are drawn before the points (to
>> allow for grids and polygons); for grids and polygons sp.layout is
>> drawn afterwards (so the item will not be overdrawn by the grid and/or
>> polygon). Although a matter of taste, transparency may help when
>> combining things. "
>>
>> But, beyond what I have tried so far, I can't figure out how to write
>> the code so that sa.shp is drawn first.
>>
>> The second question:
>>
>> 2. Is there an option to pass to:
>>
>> text1 <- list("sp.text", c(360000, -3210000),
>>             paste("Overall mean yield =",
>> round(mean(md.shp at data[-c(22,69), 4]), 0), "kg/ha"),
>>             col ="red", cex = 1)
>>
>> so that the text is left-justified on the coordinates  c(360000,
>> -3210000)? At the moment it seems that the text is centered at this
>> location.
>>
>> Thanks in advance for any help you can provide.
>>
>> Best, Lyndon
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> --
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of Münster
> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
> http://www.52north.org/geostatistics      e.pebesma at wwu.de
>



More information about the R-sig-Geo mailing list