[R] adding text to spplot

Oscar Perpiñan Lamigueiro oscar.perpinan at upm.es
Wed Jul 13 18:45:58 CEST 2011


Hi,

help(spplot):

     The ‘sp.layout’ argument is either a single layout item, or a list
     with a layout items. A layout item is a list with its first
     argument the name of the layout function to be called: ‘sp.points’
     for SpatialPoints, ‘sp.polygons’ for SpatialPolygons object,
     ‘sp.lines’ for a SpatialLines object, and ‘sp.text’ for text to
     place. The second argument contains the object (or text) to be
     plotted; remaining arguments are passed to the corresponding
     ‘panel.*’ functions.

And first example of help(spplot):

     data(meuse)
     coordinates(meuse) <- ~x+y
     l2 = list("SpatialPolygonsRescale", layout.north.arrow(), offset =
     c(181300,329800), scale = 400)
     l3 = list("SpatialPolygonsRescale", layout.scale.bar(), offset =
     c(180500,329800), scale = 500, fill=c("transparent","black"))
     l4 = list("sp.text", c(180500,329900), "0")
     l5 = list("sp.text", c(181000,329900), "500 m")
     
     spplot(meuse, c("ffreq"), sp.layout=list(l2,l3,l4,l5),
     col.regions= "black", pch=c(1,2,3),
     key.space=list(x=0.1,y=.95,corner=c(0,1)))

Bye, 

Oscar.


El Wed, 13 Jul 2011 17:18:14 +0200
Matevž Pavlič <matevz.pavlic at gi-zrmk.si> escribió:
> 
> Hi,
> still have troubles,  if I have a code like this :
> 
> spplot(enaD2, "var1.pred",sp.layout=pts,  main = "globina 60 cm",
> sub="D2", col.regions=terrain.colors(64), contour=T)
> 
> i get a nice plot with contours but without text.
> 
> If ia use your code :
> 
> spplot(enaD2, "var1.pred",sp.layout=pts,  main = "globina 60 cm",
> sub="D2", col.regions=terrain.colors(64), contour=T, panel =
> function(x,y,z,...) { sp.points(ena, pch=20, cex=1.5, col="red")
> sp.text(coordinates(ena), ena$ime) }    )
> 
> I get eeverything else but the actual spplot (just points and labels
> and a key on the right).
> 
> any ideas?
> 
> m

-------------
Oscar Perpiñán Lamigueiro
Dpto. de Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com



More information about the R-help mailing list