View source: R/geom_connector.R
geom_connector | R Documentation |
geom_connector()
is a variation of ggplot2::geom_step()
.
Its variant geom_bar_connector()
is particularly adapted to
connect bars.
geom_connector(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
width = 0.1,
continuous = FALSE,
na.rm = FALSE,
orientation = NA,
show.legend = NA,
inherit.aes = TRUE,
...
)
geom_bar_connector(
mapping = NULL,
data = NULL,
stat = "prop",
position = "stack",
width = 0.9,
continuous = FALSE,
add_baseline = TRUE,
na.rm = FALSE,
orientation = NA,
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 |
stat |
The statistical transformation to use on 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
|
width |
Bar width (see examples). |
continuous |
Should connect segments be continuous? |
na.rm |
If |
orientation |
The orientation of the layer. The default ( |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to
|
add_baseline |
Add connectors at baseline? |
library(ggplot2)
# geom_bar_connector() -----------
ggplot(diamonds) +
aes(x = clarity, fill = cut) +
geom_bar(width = .5) +
geom_bar_connector(width = .5, linewidth = .25) +
theme_minimal() +
theme(legend.position = "bottom")
ggplot(diamonds) +
aes(x = clarity, fill = cut) +
geom_bar(width = .5) +
geom_bar_connector(
width = .5,
continuous = TRUE,
colour = "red",
linetype = "dotted",
add_baseline = FALSE,
) +
theme(legend.position = "bottom")
ggplot(diamonds) +
aes(x = clarity, fill = cut) +
geom_bar(width = .5, position = "fill") +
geom_bar_connector(width = .5, position = "fill") +
theme(legend.position = "bottom")
ggplot(diamonds) +
aes(x = clarity, fill = cut) +
geom_bar(width = .5, position = "diverging") +
geom_bar_connector(width = .5, position = "diverging", linewidth = .25) +
theme(legend.position = "bottom")
# geom_connector() -----------
ggplot(mtcars) +
aes(x = wt, y = mpg, colour = factor(cyl)) +
geom_connector() +
geom_point()
ggplot(mtcars) +
aes(x = wt, y = mpg, colour = factor(cyl)) +
geom_connector(continuous = TRUE) +
geom_point()
ggplot(mtcars) +
aes(x = wt, y = mpg, colour = factor(cyl)) +
geom_connector(continuous = TRUE, width = .3) +
geom_point()
ggplot(mtcars) +
aes(x = wt, y = mpg, colour = factor(cyl)) +
geom_connector(width = 0) +
geom_point()
ggplot(mtcars) +
aes(x = wt, y = mpg, colour = factor(cyl)) +
geom_connector(width = Inf) +
geom_point()
ggplot(mtcars) +
aes(x = wt, y = mpg, colour = factor(cyl)) +
geom_connector(width = Inf, continuous = TRUE) +
geom_point()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.