make_raster_map | R Documentation |
Plot a raster on a map. If a RasterStack is provided instead, facet_wrap will be used to plot the raster layers on separate maps, and nrow specifies the number of rows of maps (note: they will be plotted by row rather than by column). The names of the raster layers in the stack will be used as titles, and the maps will all use the same color scale.
make_raster_map(
rast,
title = NULL,
xlim = NULL,
ylim = NULL,
xbreaks = NULL,
ybreaks = NULL,
xlabs = NULL,
ylabs = NULL,
sec.axis.x = NULL,
sec.axis.y = NULL,
col_limits = NULL,
cm = colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow",
"#FF7F00", "red", "#7F0000"))(100),
set_extremes = FALSE,
na.value = "transparent",
rast_alpha = 1,
map_alpha = 0.8,
map_fill = "grey",
map_colour = "darkgrey",
nrow = 1,
show_legend = TRUE,
hires_land = FALSE,
...
)
rast |
Georeferenced RasterLayer or RasterStack |
title |
Optional title of the map |
xlim |
Longitude limits. Set to NULL to let the function decide. |
ylim |
Latitude limits. Set to NULL to let the function decide. |
xbreaks |
x-axis (longitude) breaks/tick positions. Set to NULL to let the function decide. |
ybreaks |
x-axis (latitude) breaks/tick positions. Set to NULL to let the function decide. |
xlabs |
x-axis (longitude) labels to use. Set to NULL to let the function decide. |
ylabs |
y-axis (latitude) labels to use. Set to NULL to let the function decide. |
sec.axis.x |
Function to define secondary axis on opposite side of plot from x axis. |
sec.axis.y |
Function to define secondary axis on opposite side of plot from y axis. |
col_limits |
Color scale limits |
cm |
Color scale |
set_extremes |
TRUE/FALSE, should values outside the range in col_limits be set to the min/max? If not, they will be transparent. Ignored if col_limits=NULL |
na.value |
Color to use for NA values in raster |
rast_alpha |
Transparency of the raster on the map, 0-1 |
map_alpha |
Transparency of landmasses on map, 0-1 |
map_fill |
Colour of the landmasses in the map |
map_colour |
Colour of the outline of the landmasses in the map |
nrow |
Number of rows of plots, for raster stacks |
show_legend |
Display the raster legend next to the map? |
hires_land |
TRUE/FALSE, use the high resolution "world2Hires" land map or lower resolution "world" map? |
... |
Extra arguments to scale_fill_gradientn() |
Raster or grid of rasters on maps with coastlines.
library(terra)
library(ggplot2)
# use SGLI L2 data and make a terra raster
data("example02_GC1SG1_202109031518L33309_L2SG_IWPRK_2000")
pts <- example02_GC1SG1_202109031518L33309_L2SG_IWPRK_2000
rast <- rasterize(as.matrix(pts[,1:2]), rast(extent=terra::ext(c(range(pts$lon),range(pts$lat)))), pts$chl, fun=mean, na.rm=TRUE)
# plot it on the map
make_raster_map(rast,title=NULL,xlim=c(-95,-42),ylim=c(39,82),trans="log10") +
theme(axis.title=element_blank(),
legend.title=element_blank(),
legend.margin=margin(0,0,0,0),
legend.box.margin=margin(-10,0,-10,-10)) +
guides(fill = guide_colourbar(title.hjust = 0,
ticks.colour = "black",
barwidth = unit(0.6, "cm"),
barheight = unit(8, "cm"),
frame.colour = "black"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.