[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 21:25:50 CET 2013


If, by shapefile, you mean a SpatialPolygons object, try:

library(latticeExtra)
library(sp)
loadMeuse(river=TRUE)
levelplot(zinc~x+y, as.data.frame(meuse),
    panel=function(x,y,subset,...) {
        panel.levelplot.points(x,y,subset,...)
        sp.polygons(meuse.riv)
    },
    aspect = "iso", scales = list(draw=FALSE), xlab=NULL, ylab = NULL,
    colorkey = list(space = "bottom"), col.symbol = 0)


On 01/19/2013 09:17 PM, Jd Devkota wrote:
> Hi Edzer
> 
> Thank you for providing the code to start with.
> 
> I used that code you gave and slightly modified and got the results close.
> I have posted the links for both level plot and spplot at the bottom of the
> post. The colors on spplot is more smooth than the levelplot but the legend
> on levelplot is better. Another thing what command do I use to add
> shapefile in level plot ?In spplot I could use sp.list command.
> 
> 
> The code I used for levelplot is as follows:
> 
> levelplot(age2100$z~age2100$x+age2100$y, as.data.frame(age2100),
> panel=panel.levelplot.points,
>     aspect = "iso", scales = list(draw=FALSE), xlab=NULL, ylab =
> NULL,cex=1.35,cuts=40,
>     colorkey = list(space = "bottom"),col.regions = rainbow(100, start =
> 3/15, end = 1),
> xlim=c(438000,468900),ylim=c(3347500,3374500))
> 
> I also tried contourplot in place of levelplot but both of them gave me the
> same plot, no change. I added contour=TRUE, label=TRUE but no change.
> 
> Please suggest what needs to be done to make the colors smooth like spplot.
> 
> Levelplot has been uploaded on
> https://www.dropbox.com/s/qng6asyn6uc3x1z/levelplot.png
> 
> Spplot can be found on https://www.dropbox.com/s/0ws3uyiyrreza6n/spplot.png
> 
> Thanks a lot.
> 
> Janesh
> 
> 
> 
> On Sat, Jan 19, 2013 at 12:29 PM, Edzer Pebesma <
> edzer.pebesma at uni-muenster.de> wrote:
> 
>>
>>
>> On 01/19/2013 07:14 PM, Oscar Perpiñan wrote:
>>>> 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.
>>>>
>>>> I think panel.levelplot.points from latticeExtra can be useful:
>>> http://latticeextra.r-forge.r-project.org/#panel.levelplot.points
>>>
>>> Best,
>>>
>>> Oscar.
>>>
>>
>> Thanks!
>>
>> Sth like
>>
>> library(latticeExtra)
>> library(sp)
>> loadMeuse()
>> levelplot(zinc~x+y, as.data.frame(meuse), panel=panel.levelplot.points,
>>     aspect = "iso", scales = list(draw=FALSE), xlab=NULL, ylab = NULL,
>>     colorkey = list(space = "bottom"))
>>
>>
>> would get you close, you might want to control xlim and ylim further.
>>
>> I'll see how I can integrate this with spplot.
>>
>> --
>> 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
>>
>> _______________________________________________
>> 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