Greetings,
I created this raster .tiff
file. It is available from here.
I had created the countieslandcover.tiff
through this code:
countieslandcover <- aggregate(landcover_countiesmap, fact = 3, fun = min, expand = F, na.rm = T)
whereby landcover_countiesmap
was the initial raster with 13988 rows and 16304 columns before downsampling . When I tried drawing this initial raster landcover_countiesmap
with 'tmap` I got an error:
Warning in fetch(.x, ..., downsample = downsample) :
with RasterIO defined, argument downsample is ignored
stars_proxy object shown at 16304 by 13998 cells.
Error: cannot allocate vector of size 870.6 Mb
Error during wrapup: cannot allocate vector of size 870.6 Mb
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
This is when I decided to downsample the raster to countieslandcover.tiff
using the aggregate
function. Upon doing so, the raster was able to be drawn using tmap
. However, the issue is that my values do not appear distinctly on the legend. Instead of '1', '2', '3' and so on they appear as '1 to 2', '2 to 3' as in the image below.
Here is the raster metadata for countieslandcover.tiff
, the result of making it coarser using the aggregate
function.
class : RasterLayer
dimensions : 4666, 5434, 25355044 (nrow, ncol, ncell)
resolution : 0.0005555558, 0.0005555558 (x, y)
extent : 34.34335, 37.36224, -1.442097, 1.150127 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : r_tmp_2022-04-19_212648_10928_21780.grd
names : Kenya_Sentinel2_LULC2016
values : 1, 10 (min, max)
Here is the code I used when drawing the raster with tmap
tm_shape(countieslandcover) + tm_raster(palette = terrain.colors(10, 0.7, rev = F), n= 10, legend.show = T, legend.is.portrait = T, colorNA = NULL) +
tm_layout(title = 'Landcover types of top 5 counties by population', legend.position = c('left', 'bottom'))
How can I make the values
appear distinctively (like separated) on both the map and the legend? My values
stands for landcover classes and will make sense if they are distinct . I tried reproject the raster to a local datum, WGS 84/ ZONE 84 S
and also played with the tm_raster
arguments to no avail.