4

I have to add a point on a existing spplot in R. I need it only for a visual purpose. I have the coordinates of the point, but I don't know how to change the code in order to add the point.

This is the code of the spplot:

spplot(pioggiaTP[1])

And this is the map obtained by running the command: spplot

The coordinates of the point are X=720731,8704 and Y=4861300,795 in the reference system WGS 84 / UTM zone 32N EPSG:32632, the same system of the plot.

Anyone can help me?

6

spplot returns a lattice plot of class "trellis". You can use the layer function from the latticeExtra package to update this object.

Example:

library("sp")
library("latticeExtra")

data(meuse)
data(meuse.grid)

coordinates(meuse.grid) <- ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")

p <- spplot(meuse.grid, "dist")
print(p)

spplot

p + layer(panel.points(x, y, col="green", pch=19), data=meuse)

spplot update

4

Another option would be to make use of the 'sp.layout' argument that comes with spplot. Note that in contrast to the approach suggested by @rcs, you are required to supply an 'sp' object (which you might have already available since you are working with spplot). Using the 'meuse.grid' dataset, your code could roughly look as follows.

## sample point
test <- data.frame(x = 180000, y = 331500)
coordinates(test) <- ~ x + y
proj4string(test) <- "+init=epsg:28992"

## display gridded data including sample point
spplot(meuse.grid, "dist", scales = list(draw = TRUE),
       sp.layout = list("sp.points", test, pch = 16, cex = 2, col = "black"))

sp.layout

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.