[R-sig-Geo] How to show the color ramp legend with discrete data in spplot ?

Edzer Pebesma edzer.pebesma at uni-muenster.de
Sat Jan 19 13:48:09 CET 2013



On 01/19/2013 01:26 PM, Jd Devkota wrote:> Hello All,
>
> I have a discontinuous dataset and I used spplot to plot the points.
>
> I was wondering whether it is possible to show the legend of the plot as
> color ramp. I saw that on continuous data. If anyone could tell me that
> would be great.

try:

library(fortunes)
fortune("there is no if")

Reflecting on that, it would involve a bit of programming, essentially
writing an appropriate panel function for lattice::levelplot. I did this
back then for polygons, found in sp:::panel.polygonsplot, which is 80
lines of R code. My guess is that it should be considerable more easy
for points. I'd be happy to receive & consider proposals.


>
> Another thing I would like to know is how can we create the horizontal
> legend. By default, the legend is vertical.
>
> I was able to shift the legend inside the plot but not horizontal. Some of
> the code I used is as follows:
>
> ##Polygon as major plot and contour as layout
> ## Put north icon on the map
> l2 = list("SpatialPolygonsRescale", layout.north.arrow(), offset =
> c(439000,3368000), scale = 4000)
> l3 = list("SpatialPolygonsRescale", layout.scale.bar(), offset =
> c(460000,3352000), scale = 5000, fill=c("transparent","black"))
> l4 = list("sp.text",c(460000,3351500),"0")
> l5 = list("sp.text",c(465000,3351500),"100 m")
> cuts=c(0,5,10,15,20,25,30,35,37,39,40)
>
> p1 <-
>
spplot(data1,sp.layout=list(list("sp.polygons",hello),l2,l3,l4,l5),axes=T,xlab="Eastings",cuts=cuts,
> ylab="Northings",lwd=2,cex=1.2,col.regions = rainbow(100, start =
3/15, end
> = 1))

Error in spplot(data1, sp.layout = list(list("sp.polygons", hello), l2,  :
  error in evaluating the argument 'obj' in selecting a method for
function 'spplot': Error: object 'data1' not found


>
> # Legend in Spplot
> names(p1$legend) <- "inside"
> p1$legend$inside$x <- 0.15
> p1$legend$inside$y <- 0.9
> plot(p1)

We don't have data1, so we can't see what you mean.

Please provide an example that, when copy and pasted, simply runs. This
means: include a library(sp), and import and use a data set available in
a package, such as the meuse data.

>
> Thank you so much.
>
> Janesh
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> 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