I am trying to improve the color shadings of a levelplot. Please take a look at the code below:
# Load required packages
library(raster)
library(rasterVis)
library(viridis)
# Download file
download.file('https://www.dropbox.com/s/caya1ja5ukpih9e/raster_thiago.tif?dl=1',
destfile="~/Desktop/raster_thiago.tif", method="auto")
# Open file
r <- readAll(raster("~/Desktop/raster_thiago.tif"))
# Raster version
plot(r, col=viridis_pal(option="D")(255))
Please note how this map looks sharp when plotted with raster::plot
. The color shadings are smooth, and you can't see any "contours" between them. However, sadly raster plots are not as customizable as levelplots.
Now, take a look at this attempt to do the same with RasterVis
:
# RasterVis version
levelplot(r, margin=FALSE,
par.settings=rasterTheme(viridis_pal(option = "D")(255)))
Do you see how this map is not as sharp as the previous one? It looks like the color palette doesn't have the same resolution, and you can see how the edges between the color gradients are not as smooth.
Is there any way to improve this look? I've tried to play around with the par.settings
and col.regions
arguments, but none of them seems to work. I am probably missing something...