Create alluvial plot. There are two main use cases: i. An alluvial plot is particularly useful for visualizing composition of the sample with respect to the flow or transition between different categorical variables over multiple stages or categories. The flows show how observations move between categories. ii. For time-series data, an alluvial plot can be considered a “time(flow-based) extension of a stacked bar chart”.
Aesthetics
Type
Aesthetics
Case 1: With categorical variables
Required
axis1 - First categorical variable axis2 - Second categorical variable y - Counts to determines the width of the alluvium
Other supported aesthetics
colour, alpha, linetype, linewidth , curvetype
Case 2: With time series data
Required
x - Time variable determining the horizontal axis y - Determines the height of the flow alluvium - Stacking variable. In our Example 2, Bangladesh and Sri Lanka.
# A tibble: 14 × 4
# Groups: Region, Year [4]
Region Year Income n
<fct> <dbl> <fct> <int>
1 Latin America & Caribbean 2021 LM 5
2 Latin America & Caribbean 2021 UM 19
3 Latin America & Caribbean 2021 H 17
4 Latin America & Caribbean 2022 LM 4
5 Latin America & Caribbean 2022 UM 19
6 Latin America & Caribbean 2022 H 18
7 Sub-Saharan Africa 2021 L 24
8 Sub-Saharan Africa 2021 LM 16
9 Sub-Saharan Africa 2021 UM 6
10 Sub-Saharan Africa 2021 H 1
11 Sub-Saharan Africa 2022 L 22
12 Sub-Saharan Africa 2022 LM 18
13 Sub-Saharan Africa 2022 UM 6
14 Sub-Saharan Africa 2022 H 1
y0 - y coordinate of the center of the circle r - radius start - starting point of the circumference end - end point of the circumference | | Other supported aesthetics | colour, alpha, linetype, linewidth , curvetype |
In the example below, geom_arc() is applied twice to show how the black arc forms the full circle, while the red arc highlights a specific portion of that circle.
library(ggforce)ggplot() +geom_arc(aes(x0 =0, y0 =0, r =8, start =1, end =8)) +geom_arc(aes(x0 =0, y0 =0, r =8, start =1, end =5), col ="red", size =2) +theme(aspect.ratio =1)
To draw pie chart and donut chart defining centre point, a radius and a start and end angle.
Aesthetic
Type
Aesthetics
Required
x0 - x-coordinate of the center of the pie chart y0 - y coordinate of the center of the circle r0 - Inner radius of the arc bar. If it is 0, the chart becomes a pie chart (no hole) r - Outer radius of the pie chart slices amount - Determines the size (angle) of each slice. Larger counts produce larger slices fill - Fill colour for each slice exploid - Moves selected slices slightly outward from the center to highlight them
# Count observations in each Income categorydf <- worldbankdata |>filter(!is.na(Region)) |>count(Region, name ="count") |>mutate(Region = Region,focus1 =0,focus2 =c(0.2, 0, 0, 0, 0, 0, 0) )df
# A tibble: 7 × 4
Region count focus1 focus2
<fct> <int> <dbl> <dbl>
1 East Asia & Pacific 1343 0 0.2
2 Europe & Central Asia 2038 0 0
3 Latin America & Caribbean 1512 0 0
4 Middle East & North Africa 756 0 0
5 North America 108 0 0
6 South Asia 288 0 0
7 Sub-Saharan Africa 1693 0 0
# Pie charta1 <-ggplot(df) +geom_arc_bar(aes(x0 =0, y0 =0,r0 =0, r =2,amount = count,fill = Region,explode = focus1 ), stat ="pie") +scale_fill_brewer(palette ="Dark2") +theme(aspect.ratio =1, legend.position ="bottom") +labs(fill ="Regions", title ="a1: with exploid = 0")# donut pie charta2 <-ggplot(df) +geom_arc_bar(aes(x0 =0, y0 =0,r0 =0.5, r =2,amount = count,fill = Region,explode = focus1 ), stat ="pie") +scale_fill_brewer(palette ="Dark2") +theme(aspect.ratio =1, legend.position ="bottom") +labs(fill ="Regions", title ="a2: with exploid = 0 and r0 = 0.5")# exploded pie chart is a pie chart where one or more slices are pulled away (separated)a3 <-ggplot(df) +geom_arc_bar(aes(x0 =0, y0 =0,r0 =0, r =2,amount = count,fill = Region,explode = focus2 ), stat ="pie") +scale_fill_brewer(palette ="Dark2") +theme(aspect.ratio =1, legend.position ="bottom") +labs(fill ="Regions", title ="a3: with exploid = 0.2 for East Asia and Pacific")a4 <-ggplot(df) +geom_arc_bar(aes(x0 =0, y0 =0,r0 =0, r =2,amount = count,fill = Region,explode = focus2 ), stat ="pie", linewidth=2) +scale_fill_brewer(palette ="Dark2") +theme(aspect.ratio =1, legend.position ="bottom") +labs(fill ="Regions", title ="a4: with exploid = 0.2 and linewidth=2")(a1|a2)/(a3|a4)
Draws directional arrows (like vectors) on a plot, which can represent directions or flows — such as wind directions, movement, or gradients. The arrow from (x, y) and pointing in the direction (dx, dy) (vector components).
A matrix-style (commonly from GGally package) visualizations to automatically display variable distributions on diagonal panels, handling both continuous and discrete data while simplifying the mapping of panel variables.
geom_autopoint() is a modified version of ggplot2::geom_point() designed mainly for scatterplot matrices. geom_point() plots points directly, while geom_autopoint() automatically applies suitable position adjustments, making it useful for exploring relationships in scatterplot matrices.