geom_diverging {ggstats} | R Documentation |
Geometries for diverging bar plots
Description
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 |
complete |
An aesthetic for those unobserved values should be completed,
see |
default_by |
Name of an aesthetic determining denominators by default,
see |
height |
Statistic used, by default, to determine the height/width,
see |
reverse |
If |
exclude_fill_values |
Vector of values from the variable associated with
the |
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:
|
labels |
Statistic used, by default, to determine the labels,
see |
labeller |
Labeller function to format labels,
see |
vjust |
Vertical adjustment for geoms that have a position
(like points or lines), not a dimension (like bars or areas). Set to
|
hide_below |
If provided, values below |
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()