geom_prop_bar | R Documentation |
geom_prop_bar()
, geom_prop_text()
and geom_prop_connector()
are
variations of ggplot2::geom_bar()
, ggplot2::geom_text()
and
geom_bar_connector()
using stat_prop()
, with custom default aesthetics:
after_stat(prop)
for x or y, and
scales::percent(after_stat(prop))
for label.
geom_prop_bar(
mapping = NULL,
data = NULL,
position = "stack",
...,
width = 0.9,
complete = NULL,
default_by = "x"
)
geom_prop_text(
mapping = ggplot2::aes(!!!auto_contrast),
data = NULL,
position = ggplot2::position_stack(0.5),
...,
complete = NULL,
default_by = "x"
)
geom_prop_connector(
mapping = NULL,
data = NULL,
position = "stack",
...,
width = 0.9,
complete = "fill",
default_by = "x"
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A 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
|
... |
Additional parameters passed to |
width |
Bar width ( |
complete |
Name (character) of an aesthetic for those statistics should be completed for unobserved values (see example). |
default_by |
If the by aesthetic is not available, name of another
aesthetic that will be used to determine the denominators (e.g. |
geom_bar_connector()
library(ggplot2)
d <- as.data.frame(Titanic)
ggplot(d) +
aes(x = Class, fill = Survived, weight = Freq) +
geom_prop_bar() +
geom_prop_text() +
geom_prop_connector()
ggplot(d) +
aes(y = Class, fill = Survived, weight = Freq) +
geom_prop_bar(width = .5) +
geom_prop_text() +
geom_prop_connector(width = .5, linetype = "dotted")
ggplot(d) +
aes(
x = Class,
fill = Survived,
weight = Freq,
y = after_stat(count),
label = after_stat(count)
) +
geom_prop_bar() +
geom_prop_text() +
geom_prop_connector()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.