[R] add single points to a level plot

lily li chocold12 at gmail.com
Thu Mar 8 16:11:34 CET 2018

Hi all,

I ran the code:
> s <- stack(replicate(2, raster(matrix(runif(100), 10))))
> xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)),
+                  z1=runif(10), z2=runif(10))
> levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) +
+   layer(sp.points(xy, pch=ifelse(pts$z1 < 0.5, 2, 3), cex=2, col=1),
columns=1) +
+   layer(sp.points(xy, pch=ifelse(pts$z2 < 0.5, 2, 3), cex=2, col=1),

And got the error:
Error in UseMethod("levelplot") :
  no applicable method for 'levelplot' applied to an object of class
"c('RasterStack', 'Raster', 'RasterStackBrick', 'BasicRaster')"

what is the problem? Thanks.

On Thu, Mar 8, 2018 at 12:07 AM, lily li <chocold12 at gmail.com> wrote:

> Hi all,
> I'm trying to add single points with known coordinates to a level plot,
> but could not find the proper answer. I got to know that layer() function
> is good for this, but I don't know which package is related to this
> function. The source is here:
> https://stackoverflow.com/questions/28597149/add-xy-points-to-raster-map-
> generated-by-levelplot
> but my question is a little different as I know the coordinates of the
> single point, rather than a range. Thanks for any help you could provide.

	[[alternative HTML version deleted]]

More information about the R-help mailing list