[R] SpatialPolygon with the max value gets no color assigned in spplot function when using
Roger Bivand
Roger.bivand at nhh.no
Sat Jan 5 15:16:34 CET 2013
Jan Hornych <jh.hornych <at> gmail.com> writes:
>
> Hi,
>
> I would like to do coloring of map regions based on the region values
> "weight". The approach I am taking is first to break regions into
> equal intervals,
>
> classIntervals(spdf$weight,4)$brks #4 intervals in this case
>
> and coloring all regions within the interval with the same color
>
> col = brewer.pal(4,"RdYlGn"))
>
If you look at the links from ?spplot, then ?levelplot explains what
is happening:
at: A numeric vector giving breakpoints along the range of ‘z’.
Contours (if any) will be drawn at these heights, and the
regions in between would be colored using ‘col.regions’. In
the latter case, values outside the range of ‘at’ will not be
drawn at all. This serves as a way to limit the range of the
data shown, similar to what a ‘zlim’ argument might have been
used for. However, this also means that when supplying ‘at’
explicitly, one has to be careful to include values outside
the range of ‘z’ to ensure that all the data are shown.
When using base graphics, the classInt package takes care to let the
user specify how to define the breakpoints (via arguments to
findIntervals), but no provision is made for spplot or lattice
graphics as such. Consequently, at present you need to add a very
small value to the top breakpoint, and subtract from the bottom
for symmetry:
brks <- classIntervals(spdf$weight,4)$brks
eps <- .Machine$double.eps
brks[1] <- brks[1] - eps
brks[length(brks)] <- brks[length(brks)] + eps
spplot(spdf, "weight", at=brks)
for some suitable value of eps. Note that the default class intervals
are by quantile.
Please consider the R-sig-geo list for questions of this kind - thank
you for including a simple working example.
Hope this clarifies,
Roger
More information about the R-help
mailing list