[R-sig-Geo] newbie: spplot/ colour ramps

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Apr 8 12:29:23 CEST 2008


Oehler, Friderike (AGPP) wrote:
> Thanks Edzer, I shall try again:
>
> 1) I would like to use spplot to map my factor "TYP" as dots of different
> colours, however the resulting plot uses the same colours for the first and
> last value (10,40). I guess that my use of the "cuts" argument is wrong, but
> I can't find any better: 
>
> LAT <-c(-6.5, -5.5, -9.5, -8.5, -7.5, -6.5, -7.5, -6.5)
> LON <-c(31.5, 31.5, 32.5, 32.5, 32.5, 32.5, 33.5, 33.5)
> TYP <-c(rep(c(10,20,30,40),2))
> a1<- as.data.frame(cbind(LON, LAT, TYP))
> coordinates(a1)<- ~ LON + LAT
> a1$TYP<-as.factor(a1$TYP)
> spplot(a1, zcol="TYP", cuts=c(10,20,30,40), col.regions=heat.colors(4),
> scales=list(draw=TRUE))
>   
I see. The plot looks fine if you omit the cuts=c(...) argument. Why do 
you want to classify using continuous values, when the variable is a factor?
> 2) I would then like to overlay these dots over the SpatialPolygonsDataFrame
> of an imported shapefile EA:
>
> points <- list("sp.points", a1, zcol="TYP",
> cuts=c(10,20,30,40),col.regions=heat.colors(4),pch=19)
> spplot(EA, zcol='ADM0_CODE', sp.layout=list(points), scales=list(draw=TRUE),
> col.regions='transparent', colorkey=FALSE, xlim=c(31,34), ylim=c(-10,-5))
>
> Does this work? I only get unicoloured dots and am not sure whether this is
> due to my problem 1) or whether there is another error.
>   
Try to spplot the points object, and pass the polygon in the sp.layout 
argument.

spplot wraps xyplot or levelplot, both in package lattice. These plots 
can only have a single variable to assign a color scale to, as far as I 
am aware.
--
Edzer




More information about the R-sig-Geo mailing list