These geometries are similar to ggplot2::geom_bar()
but provides
different set of default values.
Usage
geom_diverging(
mapping = NULL,
data = NULL,
stat = "prop",
position = position_diverging(reverse = reverse, exclude_fill_values =
exclude_fill_values, cutoff = cutoff),
...,
complete = "fill",
default_by = "total",
height = "count",
reverse = FALSE,
exclude_fill_values = NULL,
cutoff = NULL
)
geom_likert(
mapping = NULL,
data = NULL,
stat = "prop",
position = position_likert(reverse = reverse, exclude_fill_values =
exclude_fill_values, cutoff = cutoff),
...,
complete = "fill",
default_by = "x",
height = "prop",
reverse = FALSE,
exclude_fill_values = NULL,
cutoff = NULL
)
geom_pyramid(
mapping = NULL,
data = NULL,
stat = "prop",
position = position_diverging(reverse = reverse, exclude_fill_values =
exclude_fill_values, cutoff = cutoff),
...,
complete = NULL,
default_by = "total",
height = "prop",
reverse = FALSE,
exclude_fill_values = NULL,
cutoff = NULL
)
geom_diverging_text(
mapping = NULL,
data = NULL,
stat = "prop",
position = position_diverging(vjust = vjust, reverse = reverse, exclude_fill_values =
exclude_fill_values, cutoff = cutoff),
...,
complete = "fill",
default_by = "total",
height = "count",
labels = "count",
labeller = label_number_abs(hide_below = hide_below),
reverse = FALSE,
exclude_fill_values = NULL,
cutoff = NULL,
vjust = 0.5,
hide_below = NULL
)
geom_likert_text(
mapping = NULL,
data = NULL,
stat = "prop",
position = position_likert(vjust = vjust, reverse = reverse, exclude_fill_values =
exclude_fill_values, cutoff = cutoff),
...,
complete = "fill",
default_by = "x",
height = "prop",
labels = "prop",
labeller = label_percent_abs(accuracy = 1, hide_below = hide_below),
reverse = FALSE,
exclude_fill_values = NULL,
cutoff = NULL,
vjust = 0.5,
hide_below = NULL
)
geom_pyramid_text(
mapping = NULL,
data = NULL,
stat = "prop",
position = position_diverging(vjust = vjust, reverse = reverse, exclude_fill_values =
exclude_fill_values, cutoff = cutoff),
...,
complete = NULL,
default_by = "total",
height = "prop",
labels = "prop",
labeller = label_percent_abs(accuracy = 1, hide_below = hide_below),
reverse = FALSE,
exclude_fill_values = NULL,
cutoff = NULL,
vjust = 0.5,
hide_below = NULL
)
Arguments
- mapping
Optional set of aesthetic mappings.
- data
The data to be displayed in this layers.
- stat
The statistical transformation to use on the data for this layer.
- position
A position adjustment to use on the data for this layer.
- ...
Other arguments passed on to
ggplot2::geom_bar()
- complete
An aesthetic for those unobserved values should be completed, see
stat_prop()
. Passed only ifstat = "prop"
.- default_by
Name of an aesthetic determining denominators by default, see
stat_prop()
. Passed only ifstat = "prop"
.- height
Statistic used, by default, to determine the height/width, see
stat_prop()
. Passed only ifstat = "prop"
.- reverse
If
TRUE
, will reverse the default stacking order. This is useful if you're rotating both the plot and legend.- exclude_fill_values
Vector of values from the variable associated with the
fill
aesthetic that should not be displayed (but still taken into account for computing proportions)- cutoff
number of categories to be displayed negatively (i.e. on the left of the x axis or the bottom of the y axis), could be a decimal value:
2
to display negatively the two first categories,2.5
to display negatively the two first categories and half of the third,2.2
to display negatively the two first categories and a fifth of the third (see examples). By default (NULL
), it will be equal to the number of categories divided by 2, i.e. it will be centered.- labels
Statistic used, by default, to determine the labels, see
stat_prop()
. Passed only ifstat = "prop"
.- labeller
Labeller function to format labels, see
stat_prop()
. Passed only ifstat = "prop"
.- vjust
Vertical adjustment for geoms that have a position (like points or lines), not a dimension (like bars or areas). Set to
0
to align with the bottom,0.5
for the middle, and1
(the default) for the top.- hide_below
If provided, values below
hide_below
will be masked. Argument passed tolabel_number_abs()
orlabel_percent_abs()
.
Details
geom_diverging()
is designed for stacked diverging bar plots, usingposition_diverging()
.geom_likert()
is designed for Likert-type items. Usingposition_likert()
(each bar sums to 100%).geom_pyramid()
is similar togeom_diverging()
but uses proportions of the total instead of counts.
To add labels on the bar plots, simply use geom_diverging_text()
,
geom_likert_text()
, or geom_pyramid_text()
.
Examples
library(ggplot2)
ggplot(diamonds) +
aes(x = clarity, fill = cut) +
geom_diverging()
ggplot(diamonds) +
aes(x = clarity, fill = cut) +
geom_diverging(cutoff = 4)
ggplot(diamonds) +
aes(y = clarity, fill = cut) +
geom_likert() +
geom_likert_text(aes(color = after_scale(hex_bw(.data$fill))))
d <- Titanic |> as.data.frame()
ggplot(d) +
aes(y = Class, fill = Sex, weight = Freq) +
geom_diverging() +
geom_diverging_text()
ggplot(d) +
aes(y = Class, fill = Sex, weight = Freq) +
geom_pyramid() +
geom_pyramid_text()