stat_connect | R Documentation |
Connect successive points with lines of different shapes.
stat_connect(
mapping = NULL,
data = NULL,
geom = "path",
position = "identity",
...,
connection = "hv",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
connection |
A specification of how two points are connected. Can be one of the folloing:
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
stat_connect()
understands the following aesthetics. Required aesthetics are displayed in bold and defaults are displayed for optional aesthetics:
• | x or xmin or xmax | |
• | y or ymin or ymax | |
• | group | → inferred |
Learn more about setting these aesthetics in vignette("ggplot2-specs")
.
ggplot(head(economics, 20), aes(date, unemploy)) +
stat_connect(connection = "hv")
# Setup custom connections
x <- seq(0, 1, length.out = 20)[-1]
smooth <- cbind(x, scales::rescale(1 / (1 + exp(-(x * 10 - 5)))))
zigzag <- cbind(c(0.4, 0.6, 1), c(0.75, 0.25, 1))
ggplot(head(economics, 10), aes(date, unemploy)) +
geom_point() +
stat_connect(aes(colour = "zigzag"), connection = zigzag) +
stat_connect(aes(colour = "smooth"), connection = smooth)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.