hi all,
I have a plot to which i would like to add text labels. And i cant find a
way...here is the code :
enaD2<-idw(D2~1, loca=dva, newdata=grd)
pts = list("sp.points", dva, pch = 20, cex=1.5, col = "darkred
spplot(enaD2, "var1.pred",sp.layout=pts, main = "globina 60
cm", sub="D2", col.regions=terrain.colors(64), contour=T)
text information is in ena$ime field,
regards, m
[[alternative HTML version deleted]]
You may need panel function
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,subscripts,...) {
panel.polygonsplot(x,y,z,subscripts,...)
sp.text(coordinates(enaD2), enaD2$ime[subscripts])
}
HTH
Weidong Gu
On Wed, Jul 13, 2011 at 7:31 AM, Matev? Pavli? <matevz.pavlic at
gi-zrmk.si> wrote:> hi all,
>
>
>
> I have a plot to which i would like to add text labels. And i cant find a
way...here is the code :
>
>
>
> enaD2<-idw(D2~1, loca=dva, newdata=grd)
>
> pts = list("sp.points", ?dva, ?pch = 20, cex=1.5, col =
"darkred
>
> spplot(enaD2, "var1.pred",sp.layout=pts, main = "globina 60
cm", sub="D2", col.regions=terrain.colors(64), contour=T)
>
>
>
>
>
> text information is in ena$ime field,
>
>
>
> regards, m
>
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
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
-----Original Message-----
From: Weidong Gu [mailto:anopheles123 at gmail.com]
Sent: Wednesday, July 13, 2011 4:03 PM
To: Matev? Pavli?
Cc: r-help at r-project.org; r-sig-geo at r-project.org
Subject: Re: [R] adding text to spplot
You may need panel function
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,subscripts,...) {
panel.polygonsplot(x,y,z,subscripts,...)
sp.text(coordinates(enaD2), enaD2$ime[subscripts]) }
HTH
Weidong Gu
On Wed, Jul 13, 2011 at 7:31 AM, Matev? Pavli? <matevz.pavlic at
gi-zrmk.si> wrote:> hi all,
>
>
>
> I have a plot to which i would like to add text labels. And i cant find a
way...here is the code :
>
>
>
> enaD2<-idw(D2~1, loca=dva, newdata=grd)
>
> pts = list("sp.points", ?dva, ?pch = 20, cex=1.5, col =
"darkred
>
> spplot(enaD2, "var1.pred",sp.layout=pts, main = "globina 60
cm",
> sub="D2", col.regions=terrain.colors(64), contour=T)
>
>
>
>
>
> text information is in ena$ime field,
>
>
>
> regards, m
>
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
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