geom_cnt | R Documentation |
Binding for ggplot2::geom_sf()
, therefore it supports
only sf
objects.
geom_cnt(
mapping = ggplot2::aes(),
data = NULL,
stat = "sf",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
keep = 0.5,
method = c("voronoi", "straight"),
simplify = TRUE,
...
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. See |
stat |
The statistical transformation to use on the data for this layer.
See |
position |
A position adjustment to use on the data for this layer.
See |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
See |
inherit.aes |
If |
keep |
numeric, proportion of points to retain (0.05-5.0; default 0.5). See Details. |
method |
character, either |
simplify |
logical, if |
... |
Other arguments passed on to |
A Layer
ggproto object that can be added to a plot.
coord_sf()
ensures that all layers use a common CRS. You can
either specify it using the crs
param, or coord_sf()
will
take it from the first layer that defines a CRS.
Most regular geoms, such as geom_point()
, geom_path()
,
geom_text()
, geom_polygon()
etc. will work fine with coord_sf()
. However
when using these geoms, two problems arise. First, what CRS should be used
for the x and y coordinates used by these non-sf geoms? The CRS applied to
non-sf geoms is set by the default_crs
parameter, and it defaults to
NULL
, which means positions for non-sf geoms are interpreted as projected
coordinates in the coordinate system set by the crs
parameter. This setting
allows you complete control over where exactly items are placed on the plot
canvas, but it may require some understanding of how projections work and how
to generate data in projected coordinates. As an alternative, you can set
default_crs = sf::st_crs(4326)
, the World Geodetic System 1984 (WGS84).
This means that x and y positions are interpreted as longitude and latitude,
respectively. You can also specify any other valid CRS as the default CRS for
non-sf geoms.
The second problem that arises for non-sf geoms is how straight lines
should be interpreted in projected space when default_crs
is not set to NULL
.
The approach coord_sf()
takes is to break straight lines into small pieces
(i.e., segmentize them) and then transform the pieces into projected coordinates.
For the default setting where x and y are interpreted as longitude and latitude,
this approach means that horizontal lines follow the parallels and vertical lines
follow the meridians. If you need a different approach to handling straight lines,
then you should manually segmentize and project coordinates and generate the plot
in projected coordinates.
geom_cnt_text()
, geom_cnt_label()
, ggplot2::geom_sf()
library(sf)
library(ggplot2)
lake <-
sf::st_read(
system.file("extdata/example.gpkg", package = "centerline"),
layer = "lake",
quiet = TRUE
)
ggplot() +
geom_sf(data = lake) +
geom_cnt(
data = lake,
keep = 1,
simplify = TRUE
) +
theme_void()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.