I want to create a map using 'ggplot2'. My data contains shapefile (points data), polygons (European countries). Underneath the vector data, I wanted to place the raster showing extends of forests over Europe, available here. The raster size of disk is 150 MB, has dimension of 46000 and 65000. To use it in ggplot, I need to first convert it to dataframe:
But, I got an error:
Error: cannot allocate vector of size 11.1 G. I do not understand why I got this error? How to make sure that I can plot my raster with vector data using
# read raster forest <- raster(paste(getwd(), "eea_r_3035_100_m_forest-area-2015_p_2015_v1_r1.tif", sep = "/")) # convert to dataframe for ggplot2() forest_df <- as.data.frame(forest, xy = TRUE) # Plot the raster data on top of European countries ggplot(data = europe) + geom_fs() + geom_raster(data = forest)
I have increased my
memory.limit(12000) and this allows me to create a
dataframe or a
stars object that I can both plot with
ggplot2. But, the display still takes forewer. When I visualize the map in ArcGIS or QGIS, the plotting takes a second. Isn't there something as efficient to plot rasters and use them in a map in R?
tmap::tm_raster() seems promissing but other suggestions are welcome!