I am trying to plot some data from the Malaria Atlas Project. Therefore, I looked in the vignette and used an example for getting started:
if (!require("malariaAtlas")) install.packages("malariaAtlas")
shape <- getShp(ISO = "MDG", admin_level = "admin1")
raster <- getRaster(dataset_id = "Explorer__2020_Global_PfPR", shp = shape, year = 2013)
p <- autoplot(object = raster,
legend_title = "",
plot_titles = FALSE,
fill_colour_palette = "PuBu")
resulting in the following graph:
and the warning message:
In geom_spatraster(data = object, use_coltab = use_coltab, ...): Ignoring unknown parameters:
legend_title
,plot_titles
, andfill_colour_palette
The alternative plotting version autoplot_MAPraster
enables some customization:
p <- autoplot_MAPraster(object = raster,
legend_title = "",
plot_titles = FALSE,
fill_colour_palette = "PuBu")
For my application, I need to customize the graphs (legend color and title, plot shapes over the raster, custom title, ...). Therefore, I checked the source code and modified the autoplot.MAPshp code without problems, but I don't know how to get ggplot2::geom_raster(data = object[object$raster_name == rastername,], ggplot2::aes_string(x="x", y="y", fill = "z"))
working for the autoplot.MAPraster code. In particular, object[object$raster_name == rastername,]
, where object = raster
, I get an error:
Error in h(simpleError(msg, call)) :
Error in evaluating the argument 'i' in selecting a method for function '[': [subset] invalid name(s)
My goal would be a (for me) working version of the source code for autoplot.MAPraster, that can be modified.
EDIT
For better differentiation of the different parts of the map, it would be useful to transfer the previously calculated country boundaries (shapes) on top of the existing raster.
shape <- getShp(ISO = "MDG", admin_level = "admin1")
autoplot(shape)
From the autoplot.MAPraster code something like
p <- p + geom_polygon(data = shape, aes_string(x = "long", y = "lat", group = "group"), alpha = 0, colour = "grey40")
could do the job. For me, this results in error massage:
Error in
geom_polygon()
: ! Problem while computing aesthetics. i Error occurred in the 3rd layer. Caused by error: ! Object 'group' not found