[R-sig-Geo] spplot handling of overlapping points?
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Fri Mar 2 21:48:36 CET 2012
Don,
spplot essentially does this:
df = data.frame(x=runif(100),y=runif(100),z=rnorm(100))
library(lattice)
xyplot(y~x,groups=cut(df$z,5),df,pch=16,cex=5, col=grey((1:5)/6),
asp="iso")
for SpatialPointsDataFrame objects. So yes, it seems that the plotting
order is determined by value.
I guess that what you would have liked is the data order, i.e.
xyplot(y~x,col=grey((1:5)/6)[cut(df$z,5)],df,pch=16,cex=5)
and I think that is more reasonable to expect (and would allow for
randomization).
Best regards,
On 03/02/2012 09:03 PM, MacQueen, Don wrote:
> I have a SpatialPointsDataFrame object in which many points are very close
> together, such that the markers (plotting characters) tend to overlap. (Of
> course, this depends on marker size and the scale at which I plot; if I
> "zoom in" there is less overlap.)
>
> It appears that when markers overlap, spplot() places a marker associated
> with the larger value after, and therefore on top of, a marker associated
> with a smaller value.
>
> Am I correct? Or more generally, what is the algorithm that determines the
> order in which markers are added?
>
>
> I have searched ?spplot and related help pages and haven't found an
> explanation (at least, not yet).
>
> I can add that I don't believe markers are placed in the order in which
> they appear in the SpatialPointsDataFrame. I say this because when I
> attempt to reproduce an spplot using base graphics plot() I have to sort
> from smallest to largest value to succeed.
>
> I can probably provide a small reproducible example if necessary, but I'm
> hoping it's not necessary.
>
> Here are my actual commands.
>
> tmps is the SpatialPointsDataFrame.
> tmp is coordinates(tmps)
> (they have the same number of rows in the same order)
>
> Note that I'm using the cuts argument to break a continuous variable
> ('cpm2') into bins. I have carefully matched the colors in tmps$col2 with
> the cbin.cols object passed to spplot(), and the break points for the bin
> boundaries, so I believe that everything else that could affect the final
> appearance, other than the order in which the markers are placed, is
> controlled.
>
> #1 using spplot
> spplot(tmps,c('cpm2'),
> key.space='right',
> legendEntries=cbin.lbls,
> cuts=cbin.brks,
> col.regions=cbin.cols,
> cex=0.4)
>
> #2 using base graphics
> plot(tmp[,1],tmp[,2], asp=1, cex=0.6, pch=16, col=tmps$col2)
>
>
>
> Thanks
> -Don
>
--
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