Ask Your Question
2

How can I use level plot in R to combine mono-colored raster layers that have overlapping data?

asked 2021-12-19 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-01-25 03:00:00 +0000

ladyg gravatar image

To combine mono-colored raster layers in R that have overlapping data using level plot, you can follow these steps:

  1. Load the necessary libraries:
library(raster)
library(lattice)
  1. Import the raster files:
r1 <- raster("raster1.tif")
r2 <- raster("raster2.tif")
  1. Use raster::merge to combine the rasters:
r_merged <- merge(r1, r2)
  1. Use levelplot() to plot the merged raster layers:
levelplot(r_merged)

The resulting plot will show the combination of the two original raster layers with overlapping data. To customize the color scheme, you can use the "col.regions" parameter in levelplot(). For example:

levelplot(r_merged, col.regions = rev(terrain.colors(255)))

This will use a color scheme from the "terrain.colors" function and reverse the order of the colors.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-19 11:00:00 +0000

Seen: 12 times

Last updated: Jan 25 '22