[R-sig-Geo] drawing order in spplot and Line width in sp maps

Mikhail Titov mlt at gmx.us
Sat Mar 30 21:43:43 CET 2013


On Sat, Mar 30, 2013 at  8:35 AM, Edzer Pebesma <edzer.pebesma at uni-muenster.de> wrote:
> Thanks Mikhail,
>
> lwd seems to work if you preceed the spplot command with a
>
> set_Polypath(FALSE)

Thank you for making these wonderful packages!

This did the trick! I would never ever guess what was missing...

However this breaks colors for _sp.polygons_ if several were used :(
E.g. in my example I had

,----[ Only first color is effective with set_Polypath(FALSE) ]
| l.wshd <- list("sp.polygons", bdry, col=c("magenta", "blue"), lwd=1.5)
`----

So I had to have a logical block in panel function

,----[ snippet from a function supplied as panel ]
|          set_Polypath(FALSE)
|          panel.polygonsplot(...)
|          set_Polypath(TRUE)
|          sp.panel.layout(list(l.wshd, l.streams, l.struc))
`----

I guess it is hard to hit 2 birds with 1 stone...

> I just committed a change to sp on r-forge that makes it work too
> without setting this command.

I'll check it out once it propagates to a binary package @CRAN.

Also I feel like that documentation is misleading a bit regarding _cuts_
saying that it is for SpatialPointsDataFrame only. It appears that it does
change # of breaks for polygon just fine.


P.S. I thought I found an answer to my question about padding when I came
across [1]. However it looks like axis.padding is not for z values...

> On 03/30/2013 06:12 AM, Mikhail Titov wrote:
>> Hi, All!
>> 
>> I know I'm excavating an old thread[1] (and top posting) but that is
>> exactly what bugs me.
>> 
>> I am surprised to see that I can't pass lwd directly to spplot's main
>> plot and not extra layouts. I can pass lwd to sp.polygons but not to
>> spplot directly :( Here is an incomplete snippet showing what I've tried
>> 
>> ,----[ How do I change line width of shp polygons supplied to spplot? ]
>> | spplot(shp, names(d), col="grey80", lwd=5, cuts=5,
>> | #        par.settings = simpleTheme(lwd=3),
>> |       par.settings = list(superpose.polygon = list(lwd=5)),
>> |        panel = function(...) {
>> | #          panel.polygonsplot(..., lwd=3)
>> |          panel.polygonsplot(...)
>> |          sp.panel.layout(list(l.wshd, l.streams, l.struc))
>> |          if (panel.number()==1) {
>> |            sp.panel.layout(list(l.north, l.scale.bar, l.scale.text))
>> |          }
>> |        },
>> |        colorkey = list(
>> |          labels=list(
>> |            at = labelat,
>> |            labels = labeltext
>> |            )
>> |          ),
>> |        names.attr=droplevels(unique(rest$case)),
>> |        col.regions=rev(greens(14, .6))[-1])#rev(heat.colors(100)))
>> `----
>> 
>> I see that lwd for my layouts apply well, e.g., for l.wshd & l.streams
>> in the example above. However I can't seem to figure out how to make shp
>> lines thinner. I do have several variables to plot on a few panels.
>> 
>> Did I miss something?
>> 
>> P.S. Not quite related question but how does levelplot (?) estimates
>> color scale labels? If I leave colorkey alone, I get misplaced labels
>> provided cuts=5. For now, I do something like
>> 
>> ,----[ Dirty fix for ticks & label alignment ]
>> | dd.rng <- range(unlist(dd), finite=TRUE)
>> | delta <- diff(dd.rng)
>> | labelat <- seq(dd.rng[1] - delta*.07, dd.rng[2] + delta*.07, length.out=7)
>> | labeltext <- format(exp(labelat), digits=2)
>> `----
>> 
>> I feel like there is almost a standard function for that but I can't
>> recall its name. Would you mind reminding if there is any?

Footnotes: 
[1]  https://r-forge.r-project.org/scm/viewvc.php/pkg/R/levelplot.R?view=markup&root=lattice

-- 
Mikhail



More information about the R-sig-Geo mailing list