These geometries are similar to ggplot2::geom_bar()
but provides
different set of default values.
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
)
Optional set of aesthetic mappings.
The data to be displayed in this layers.
The statistical transformation to use on the data for this layer.
A position adjustment to use on the data for this layer.
Other arguments passed on to ggplot2::geom_bar()
An aesthetic for those unobserved values should be completed,
see stat_prop()
. Passed only if stat = "prop"
.
Name of an aesthetic determining denominators by default,
see stat_prop()
. Passed only if stat = "prop"
.
Statistic used, by default, to determine the height/width,
see stat_prop()
. Passed only if stat = "prop"
.
If TRUE
, will reverse the default stacking order.
This is useful if you're rotating both the plot and legend.
Vector of values from the variable associated with
the fill
aesthetic that should not be displayed (but still taken into
account for computing proportions)
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.
Statistic used, by default, to determine the labels,
see stat_prop()
. Passed only if stat = "prop"
.
Labeller function to format labels,
see stat_prop()
. Passed only if stat = "prop"
.
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,
and 1
(the default) for the top.
If provided, values below hide_below
will be masked.
Argument passed to label_number_abs()
or label_percent_abs()
.
geom_diverging()
is designed for stacked diverging bar plots, using
position_diverging()
.
geom_likert()
is designed for Likert-type items. Using
position_likert()
(each bar sums to 100%).
geom_pyramid()
is similar to geom_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()
.
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()
Run the code above in your browser using DataLab