简体   繁体   中英

Plotting Raster object with points at exact position

I have a raster object to which I would like to add points. However, when I change plot size, by making it full screen for example, the points change their positions.

Is there a way to give them exact positions, independent of plot size?

reproducable code:

r<- raster(nrows=10, ncols=10) r <- setValues(r, 1:ncell(r)) plot(r) points(x=-50,y=20) points(x=-50,y=-90)

I'm not allowed to post images. But the lower point gets out of the coloured region when I make the device smaller or moves more into the coloured region when I make the device bigger.

Cheers

this problem has been exposed here too: plotting spatial points over a raster layer in r .

I tried to overpass it by creating a SpatialPointsDataFrame:

r<- raster(nrows=10, ncols=10)
r <- setValues(r, 1:ncell(r))
plot(r)
points(x=-50,y=20)
points(x=-50,y=-90)


coor1<- data.frame(Lat=-50,Lon=20)


point1 <- SpatialPointsDataFrame(
  data.frame(coor1$Lon,coor1$Lat),
  data.frame('Landriano')
)

x11()
plot(r)
plot(point1, add=T)

The only solution I see is once you overlap the point over the raster you shouldn't change the plot window size. Otherwise the points will be shifted somewhere randomly...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM