get_map | R Documentation |
Given a specific domain, a map is returned on that domain. The function is
intended to be used in conjunction with geom_geocontour
and /
or geom_georaster
when plotting using ggplot()
.
get_map(dom = NULL, map = "world", polygon = TRUE, ...)
dom |
A |
map |
The map database from which to get the map data. The default is
|
polygon |
Logical. Whether to return the data as polygons ( |
... |
Not used. |
A data frame with columns "x", "y", and for polygon = TRUE
an
additional "group" column.
# Define a domain and make some data
arr <- array(dim = c(200, 200))
for (i in 1:200) {
for (j in 1:200) {
arr[i, j] <- sin(i / 10) + sin(j / 10)
}
}
dom <- define_domain(10, 60, 200, 10000)
geo <- geofield(arr, domain = dom)
data <- data.frame(geo = geolist(geo))
# Use polygons
map <- get_map(geo)
ggplot() +
geom_polygon(
aes(x, y, group = group), map,
fill = "seagreen", colour = "grey10"
) +
geom_geocontour(aes(geofield = geo, colour = after_stat(level)), data) +
coord_equal(expand = FALSE) +
theme_harp_map()
# Use paths
map <- get_map(geo, polygon = FALSE)
ggplot() +
geom_georaster(aes(geofield = geo), data) +
geom_path(aes(x, y), map, colour = "grey30") +
coord_equal(expand = FALSE) +
theme_harp_map()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.