I am trying to plot a rasterLayer
object on a plot composed of two figures using screen
First - a working case scenario when we only have one image:
library(raster)
f <- system.file("external/test.grd", package="raster")
rst <- raster(f)
plot(rst)
points(180000, 332000, col="red", pch=19)
Everything looks fine and the image looks like this:
However when I split the screen into two and try to plot the same figure using only half of the plotting region I get the following:
library(raster)
f <- system.file("external/test.grd", package="raster")
rst <- raster(f)
class(rst)
figs <- rbind(c(0, 0.5, 0, 1), # Screen1
c(0.5, 1, 0, 1) # Screen2
)
screenIDs <- split.screen(figs)
screen(screenIDs[1])
plot(rst)
points(180000, 332000, col="red", pch=19)
It seems like the main image of the raster shape is being drawn correctly. However for some reason it then captures the entire plotting region and adds a boundary lines on it. After that subsequent calls to the plot (like points
) add points on the whole figure rather than staying in the first half of it.
Any ideas how to solve or bypass this are most appreciated.
You can use layout
instead of split.screen
. Demonstrated here, as in your example, with a simple layout of just 1 row of two equal-sized panels. For how to get more complex layouts, have a look at ?layout
layout(matrix(c(1,2), 1, 2, byrow = TRUE))
plot(rst)
points(180000, 332000, col="red", pch=19)
plot(1:10,1:10) # a dummy plot to put in the right hand panel
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.