geom_loc | R Documentation |
'geom_loc' is a wrapper around ggplot2::geom_sf()
designed
for visualizing spatial point data. It supports both sf
objects and tabular data frames
with longitude and latitude columns, automatically transforming them into the specified
coordinate reference system (CRS).
geom_loc(
data,
lon = NULL,
lat = NULL,
crs = "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs",
mapping = ggplot2::aes(),
...
)
data |
A data frame, tibble, or |
lon |
A character string. The name of the longitude column in |
lat |
A character string. The name of the latitude column in |
crs |
A character string. The target coordinate reference system (CRS) for the data.
Defaults to |
mapping |
Aesthetic mappings created by |
... |
Additional parameters passed to |
This function simplifies the process of visualizing spatial data in ggplot2 by automatically
handling CRS transformations and providing an interface for both sf
and tabular data.
If the input is a tabular data frame, it will be converted to an sf
object using the
specified longitude and latitude columns.
See ggplot2::geom_sf()
for details on additional parameters
and aesthetics.
A ggplot2 layer for visualizing spatial point data, either from an 'sf' object or a tabular data frame with longitude and latitude columns, after transforming the data to the specified coordinate reference system (CRS).
geom_boundary_cn
# Generate a random dataset with latitude and longitude
set.seed(123)
data_sim <- data.frame(
Longitude = runif(100, 80, 120),
Latitude = runif(100, 28, 40),
Category = sample(c("Type A", "Type B", "Type C"), 100, replace = TRUE)
)
# Visualize the data with China's boundaries
ggplot() +
geom_boundary_cn() +
geom_loc(
data = data_sim, lon = "Longitude", lat = "Latitude",
mapping = aes(color = Category), size = 1, alpha = 0.7
) +
theme_minimal()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.