View source: R/geom-chicklet.R
geom_chicklet | R Documentation |
This geom behaves much like ggplot2::geom_col()
but provides the option to
set a corner radius to turn sharp-edged bars into rounded rectangles; it also
sets some sane defaults for making chicklet charts.
geom_chicklet( mapping = NULL, data = NULL, position = ggplot2::position_stack(reverse = TRUE), radius = grid::unit(3, "pt"), ..., width = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) GeomChicklet
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
radius |
corner radius (default 3pt) |
... |
Other arguments passed on to |
width |
Bar width. By default, set to 90% of the resolution of the data. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
An object of class GeomChicklet
(inherits from GeomRrect
, Geom
, ggproto
, gg
) of length 7.
A sample of the output from geom_chicklet()
:
geom_chicklet()
understands the following aesthetics:
x
y
alpha
colour
fill
group
linetype
size
Use both fill
and group
when you want a fill colour per-segment but
want to order the segments by another column (as in the Examples).
the chicklet/segment stack positions are default set to be reversed (i.e. left-to-right/bottom-to-top == earliest to latest order).
library(ggplot2) data("debates2019") # set the speaker order spkr_ordr <- aggregate(elapsed ~ speaker, data = debates2019, sum) spkr_ordr <- spkr_ordr[order(spkr_ordr[["elapsed"]]),] debates2019$speaker <- factor(debates2019$speaker, spkr_ordr$speaker) ggplot(debates2019) + # use 'group' to control left-to-right order geom_chicklet(aes(speaker, elapsed, group = timestamp, fill = topic)) + scale_y_continuous(expand = c(0, 0.01), position = "right") + coord_flip() + labs(x = NULL, y = "Minutes Spoken", fill = NULL) + theme_minimal() + theme(panel.grid.major.y = element_blank()) + theme(legend.position = "bottom")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.