View source: R/geom_spatial_rgb.R
geom_spatial_rgb | R Documentation |
geom_spatial_rgb
and stat_spatial_rgb
allow users to plot three-band RGB
rasters in ggplot2, using these layers as background base maps for other
spatial plotting. Note that unlike ggplot2::geom_sf, this function does
not force ggplot2::coord_sf; for accurate mapping, add
ggplot2::coord_sf with a crs
value matching your input raster as a layer.
geom_spatial_rgb(
mapping = NULL,
data = NULL,
stat = "spatialRGB",
position = "identity",
...,
hjust = 0.5,
vjust = 0.5,
interpolate = FALSE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
scale = NULL
)
stat_spatial_rgb(
mapping = NULL,
data = NULL,
geom = "raster",
position = "identity",
na.rm = FALSE,
show.legend = FALSE,
inherit.aes = TRUE,
scale = NULL,
...
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. In addition to the three options described in ggplot2::geom_raster, there are two additional methods: If a If a length-1 character vector, this function will attempt to load the object via terra::rast. |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
hjust , vjust |
horizontal and vertical justification of the grob. Each justification value should be a number between 0 and 1. Defaults to 0.5 for both, centering each pixel over its data location. |
interpolate |
If |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
scale |
Integer. Maximum (possible) value in the three channels.
If |
geom |
The geometric object to use to display the data, either as a
|
Other visualization functions:
combine_overlays()
,
raster_to_raw_tiles()
,
vector_to_overlay()
## Not run:
simulated_data <- data.frame(
id = seq(1, 100, 1),
lat = runif(100, 44.04905, 44.17609),
lng = runif(100, -74.01188, -73.83493)
)
simulated_data <- sf::st_as_sf(simulated_data, coords = c("lng", "lat"))
simulated_data <- sf::st_set_crs(simulated_data, 4326)
output_tiles <- get_tiles(simulated_data,
services = c("ortho"),
resolution = 120
)
merged_ortho <- tempfile(fileext = ".tif")
merge_rasters(output_tiles[["ortho"]], merged_ortho)
merged_stack <- terra::rast(merged_ortho)
library(ggplot2)
ggplot() +
geom_spatial_rgb(
data = merged_ortho,
mapping = aes(
x = x,
y = y,
r = red,
g = green,
b = blue
)
) +
geom_sf(data = simulated_data) +
coord_sf(crs = 4326)
ggplot() +
geom_spatial_rgb(
data = merged_stack,
mapping = aes(
x = x,
y = y,
r = red,
g = green,
b = blue
)
) +
geom_sf(data = simulated_data) +
coord_sf(crs = 4326)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.