1  A

1.1 geom_abline

Package

ggplot2 (Wickham 2016)

Description

Draw a straight line (\(Y=mX+c\)) for a given slope (\(m\)) or/and intercept (\(c\)).

Aesthetics

Type Aesthetics
Required intercept and/or slope
Other supported aesthetics colour, alpha, linetype, linewidth

See also

geom_point, geom_vline, geom_hline, geom_smooth,

Example

a1 <- ggplot() +
  geom_abline(intercept = 0, slope = 1) +
  labs(title = "a1: geom_abline only") +
  theme(aspect.ratio = 1)
a2 <- ggplot(happiness_gdp_income, aes(y =HappinessScore2016, x = HappinessScore2015)) +
  geom_abline(intercept = 0, slope = 1) +
  geom_point() +
  labs(title = "a2: geom_abline \n and geom_point") +
  theme(aspect.ratio = 1)
a1 | a2

1.2 geom_alluvium

Package

ggalluvial(Brunson and Read 2019; Brunson 2020)

Description

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.
Other supported aesthetics colour, alpha, linetype, linewidth
curvetype

See also

geom_stratum, geom_flow, geom_line geom_lode

Example 1

This example shows the distribution of income level categories in 2021 and 2022 in the regions Sub-Saharan Africa and Latin America & Caribbean.

library(ggalluvial)
e1data <- worldbankdata |>
  select(Country, Region, Year, Income) |>
  filter(Year > 2020) |>
  filter(Region %in% c("Sub-Saharan Africa", "Latin America & Caribbean")) |>
  group_by(Region, Year, Income) |>
  summarise(n = n()) |>
  drop_na()
e1data
# 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
a1 <- e1data |>
  ggplot(aes(y = n, axis1 = Income, axis2 = Region)) +
  geom_alluvium(aes(fill = as.factor(Year)), width = 1 / 12) +
  scale_fill_brewer(palette = "Dark2") +
  labs(title = "a1: geom_alluvium only")

a2 <- e1data |>
  ggplot(aes(y = n, axis1 = Income, axis2 = Region)) +
  geom_alluvium(aes(fill = as.factor(Year)), width = 1 / 12) +
  geom_stratum(width = 1 / 12, fill = "black", color = "grey") +
  geom_label(stat = "stratum", aes(label = after_stat(stratum))) +  scale_fill_brewer(palette = "Dark2") +
  labs(title = "a2: geom_alluvium, \n geom_stratum and geom_label")
a1 / a2

Example 2

e2data <- worldbankdata |>
  filter(Country %in% c("Bangladesh", "Sri Lanka"),
         Year >= 2013, Year <= 2021) |>
  select(Country, Year, Electricity)
e2data
# A tibble: 18 × 3
   Country     Year Electricity
   <fct>      <dbl>       <dbl>
 1 Bangladesh  2013        61.5
 2 Bangladesh  2014        62.4
 3 Bangladesh  2015        74  
 4 Bangladesh  2016        75.9
 5 Bangladesh  2017        88  
 6 Bangladesh  2018        86.9
 7 Bangladesh  2019        92.2
 8 Bangladesh  2020        96.2
 9 Bangladesh  2021        99.0
10 Sri Lanka   2013        90.2
11 Sri Lanka   2014        92.7
12 Sri Lanka   2015        94.3
13 Sri Lanka   2016        97.5
14 Sri Lanka   2017        97.5
15 Sri Lanka   2018        99.6
16 Sri Lanka   2019        99.8
17 Sri Lanka   2020       100.0
18 Sri Lanka   2021       100  
p1 <-  ggplot(e2data, aes(x = Year,
             y = Electricity,
             alluvium = Country,
             stratum = Country,
             fill = Country)) +
  geom_alluvium(alpha = 0.6) +
  scale_x_continuous(breaks = 2013:2021) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
  labs(title = "a1: geom_alluvium only",
       x = "Year",
       y = "Electricity",
       fill = "Country")

p2 <-  ggplot(e2data, aes(x = Year,
             y = Electricity,
             alluvium = Country,
             stratum = Country,
             fill = Country)) +
  geom_alluvium(alpha = 0.6) +
  geom_stratum(width = 0.4, color = "black") +
  scale_x_continuous(breaks = 2013:2021) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
  labs(title = "a2: geom_alluvium and geom_stratum",
       x = "Year",
       y = "Electricity",
       fill = "Country")
p1/p2

1.3 geom_arc

Package

ggforce(Pedersen 2022)

Description

Draw a circle or a segment of a circle.

Aesthetic

Type Aesthetics
Required x0 - x coordinate of the center of the circle

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 |

required aesthetics

See also

geom_arc2, geom_arc_bar

Example

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)

1.4 geom_arc_bar

Package

ggforce(Pedersen 2022)

Description

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
Other supported aesthetics color, linewidth, linetype, alpha, lineend

See also

geom_arc, geom_arc_bar

Example

# Count observations in each Income category
df <- 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 chart
a1 <- 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 chart
a2 <- 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)

1.5 geom_area

Package

ggplot2 (Wickham 2016)

Description

Create an area plot. This cover the space between x-axis and line that connects the data points.

Aesthetics

Type Aesthetics
Required
x, y
Other supported aesthetics color, linewidth, linetype, alpha, lineend

See also

geom_line, geom_ribbon, geom_arrow_segement

Example

a1 <- worldbankdata |>
  filter(Country == "Bangladesh") |>
  filter(Year >= 2013 & Year <= 2021) |>
  ggplot(aes(x = Year, y = Electricity)) +
  geom_area(alpha = 0.5) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
  scale_x_continuous(breaks = 2013:2021) +
  labs(title = "a1: geom_area only")

a2 <- worldbankdata |>
  filter(Country == "Bangladesh") |>
  filter(Year >= 2013 & Year <= 2021) |>
  ggplot(aes(x = Year, y = Electricity)) +
  geom_area(alpha = 0.5) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
  scale_x_continuous(breaks = 2013:2021) +
  geom_point(col = "red") +
  labs(title = "a2: geom_area \n and geom_point")
a1 | a2

1.6 geom_arrow based on metR

Package

metR (Campitelli 2021)

Description

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).

Aesthetics

Type Aesthetics
Required
x, y,
dx - change in x
dy - change in y
Other supported aesthetics arrow,type, arrow.angle, arrow.length, arrow.ends, arrow.type

See also

geom_line, geom_ribbon

Example

library(metR)
data <- tibble::tibble(
  x = c(10, 20, 30, 40, 50),      # Longitude or X-coordinates
  y = c(1, 2, 3, 4, 5),           # Latitude or Y-coordinates
  dx = c(1, 0, -1, 0, 1),         # Wind direction components (change in X)
  dy = c(1, -1, 0, 1, 0)          # Wind direction components (change in Y)
)

ggplot(data, aes(x = x, y = y)) +
  geom_point(color = "#1b9e77", size = 3) +  
  geom_arrow(aes(dx = dx, dy = dy), color = "#d95f02", size = 1, arrow.type = "closed") +
  labs(title = "Wind Directions at Different Locations", x = "Longitude", y = "Latitude")

1.7 geom_arrow based on ggarrow

Package

ggarrow (van den Brand 2025)

Description

Draw arrows. Draws an arrowhead at the end of each path (the final point in the sequence)

Aesthetics

Type Aesthetics
Required x, y
Other supported aesthetics arrow,type, arrow.angle, arrow.length, arrow.ends, arrow.type

See also

geom_line, geom_ribbon

Example 1

library(ggarrow)
a1 <- worldbankdata |>
  filter(Country == "Bangladesh") |>
  filter(Year >= 2013 & Year <= 2021) |>
ggplot(aes(x=Year, y=Electricity)) +
  geom_arrow()

a2 <- worldbankdata |>
  filter(Country %in% c("Bangladesh", "Sri Lanka"),
         Year >= 2013, Year <= 2021) |>
  select(Country, Year, Electricity) |>
  ggplot(aes(x=Year, y=Electricity, colour = Country)) +
  geom_arrow()
a1|a2

Example 2

Draw a spiral based on a example dataset (whirlpool(5)) in the package.

head(whirlpool(5))
             x          y group        arc
1 3.183977e-17 -0.2600000     1 0.00000000
2 8.566542e-03 -0.2698641     1 0.01306466
3 1.775870e-02 -0.2794363     1 0.02633579
4 2.756625e-02 -0.2886869     1 0.03981769
5 3.797774e-02 -0.2975864     1 0.05351446
6 4.898043e-02 -0.3061061     1 0.06743003
ggplot(whirlpool(5), aes(x, y, colour = group)) +
  geom_arrow(
    linewidth = 1,
    arrow_head = arrow_head_wings()
  ) +
  scale_color_brewer(palette = "Set1") + 
  coord_equal()

1.8 geom_arrow_chain

Package

ggarrow (van den Brand 2025)

Description

Draw arrows in between points.

Aesthetics

Type Aesthetics
Required x, y
Other supported aesthetics arrow,type, arrow.angle, arrow.length, arrow.ends, arrow.type

See also

geom_line, geom_ribbon

Example 1

library(ggarrow)
a1 <- worldbankdata |>
  filter(Country == "Bangladesh") |>
  filter(Year >= 2013 & Year <= 2021) |>
ggplot(aes(x=Year, y=Electricity)) +
  geom_arrow_chain() + 
  labs(title = "arrow_chain only")
a2 <- worldbankdata |>
  filter(Country == "Bangladesh") |>
  filter(Year >= 2013 & Year <= 2021) |>
ggplot(aes(x=Year, y=Electricity)) +
  geom_arrow_chain() + 
  geom_point() + 
  labs(title = "arrow_chain and point")
a1|a2

1.9 geom_ash

Package

ggformula (Kaplan and Pruim 2023)

Description

Plot Average Shifted Histogram (ASH). The ASH is a nonparametric probability density estimator derived from a collection of histograms.

Aesthetics

Aesthetics

Type Aesthetics
Required x, y
Other supported aesthetics color, fill, bins, alpha, size

See also

geom_histogram, geom_density

Example

library(ggformula)
p1 <- worldbankdata |>
  filter(Income == "LM") |>
  ggplot(aes(x = Electricity)) +
   geom_ash(bins = 20, color = "#d95f02") +   labs(title="Average Shifted Histogram")
p2 <- worldbankdata |>
  filter(Income == "LM") |>
  ggplot(aes(x = Electricity)) +
  geom_histogram(aes(y = stat(density)), color = "black", fill = "gray") +
   geom_ash(bins = 20, color = "#d95f02") + labs(title = "Histogram and Average Shifted Histogram")
p1|p2

1.10 geom_autodensity

Package

ggforce (Pedersen 2022)

Description

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.

Aesthetics

Type Aesthetics
Required data
Other supported aesthetics alpha, colour, group, linetype, linewidth

See also

geom_density, geom_histogram, geom_autohistogram, geom_autopoint,

Example

library(ggplot2)
library(GGally)

# Select numeric variables
df <- happiness_gdp_income |>
  select("HappinessScore2015", "HappinessScore2016", "HappinessScore2017")
ggplot(df) +
  facet_matrix(
    vars(
      HappinessScore2015, 
      HappinessScore2016, 
      HappinessScore2017
    ),
    layer.diag = 1
  ) +
  geom_autodensity()
Warning: Removed 16 rows containing non-finite outside the scale range
(`stat_autodensity()`).

1.11 geom_autohistogram

Package

ggforce (Pedersen 2022)

Description

Aesthetics

Type Aesthetics
Required data
Other supported aesthetics alpha, colour, group, linetype, linewidth

See also

geom_histogram, geom_auotodensity, geom_auotpoint

Example

library(dplyr)
library(ggplot2)
library(GGally)

# Prepare dataset
df <- happiness_gdp_income %>%
  select(HappinessScore2015, HappinessScore2016, HappinessScore2017,
         GDPpercapita2015) %>%
  rename(GDPpercapita = GDPpercapita2015) %>%
  # Create income category
  mutate(IncomeCategory = case_when(
    GDPpercapita < 1.2 ~ "Low",
    GDPpercapita >= 1.2 & GDPpercapita < 1.4 ~ "Medium",
    GDPpercapita >= 1.4 ~ "High"
  )) %>%
  mutate(
    IncomeCategory = factor(IncomeCategory, levels = c("Low", "Medium", "High")),
    # Create discrete happiness scores by rounding
    HappinessScore2015_discrete = factor(round(HappinessScore2015)),
    HappinessScore2016_discrete = factor(round(HappinessScore2016)),
    HappinessScore2017_discrete = factor(round(HappinessScore2017))
  )

# Plot facet matrix using discrete happiness scores
ggplot(df, aes(x = .panel_x, fill = IncomeCategory)) +
  facet_matrix(
    vars(HappinessScore2015_discrete, HappinessScore2016_discrete, HappinessScore2017_discrete),
    layer.diag = 1,
    grid.y.diag = FALSE
  ) +
  geom_autohistogram(alpha = 0.7, position = "dodge") +  # diagonal histograms
  geom_autopoint(alpha = 0.6, aes(color = IncomeCategory)) +  # off-diagonal scatterplots
  scale_fill_brewer(palette = "Set2") +
  scale_color_brewer(palette = "Set2") +
  theme_minimal() +
  labs(
    fill = "Income Category",
    color = "Income Category",
    title = "Discrete Happiness Scores by Income Category",
    x = "",
    y = ""
  )

1.12 geom_autopoint

Package

ggforce (Pedersen 2022)

Description

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.

Aesthetics

Type Aesthetics
Required x, y
Other supported aesthetics alpha, colour, group, linetype, linewidth

See also

geom_line, geom_point

Example

library(ggforce)
ggplot(happiness_gdp_income,
       aes(x=GDPpercapita2015,
           y=HappinessScore2015,
           colour = Income2015)) +
  geom_point(size = 3) + labs(title = "geom_point")

ggplot(happiness_gdp_income) +
  geom_autopoint(aes(colour = Income2015)) +
  facet_matrix(vars(
    HappinessScore2015,
    GDPpercapita2015
  )) + labs(title = "geom_autopoint")

ggplot(happiness_gdp_income) +  geom_autopoint(aes(colour = Income2015)) +
  facet_matrix(vars(
    HappinessScore2015: GDPpercapita2016
  ))
Warning: Removed 84 rows containing missing values or values outside the scale range
(`geom_point()`).

1.13 geom_axis_hive

Package

ggraph (ggraph?)

Description

Allows you to annotate the axes in a hive plot with labels and color coded bars.

Aesthetics

Type Aesthetics
Required x, y
Other supported aesthetics alpha, colour, group, linetype, linewidth

See also

geom_line, geom_ribbon

Example

Suppose we want to visualise the following diagram

library(tidygraph)

Attaching package: 'tidygraph'
The following object is masked from 'package:stats':

    filter
library(ggraph)

Attaching package: 'ggraph'
The following object is masked from 'package:metR':

    scale_label_size_continuous
nodes <- data.frame(
  country = c("China", "India", "Japan",
              "Germany", "France", "Italy"),
  region = c("Asia", "Asia", "Asia",
             "Europe", "Europe", "Europe")
)

edges <- data.frame(
  from = c("China", "China", "India",
           "Japan", "India"),
  to = c("Germany", "France", "Germany",
         "Italy", "France")
)

g <- tbl_graph(nodes = nodes, edges = edges, directed = FALSE)

# Calculate node degree
g <- g |>
  activate(nodes) |>
  mutate(degree = centrality_degree())

ggraph(g, layout = "hive", axis = region, sort.by = degree) +
  geom_edge_hive() +
  geom_axis_hive(aes(colour = region), size = 3) +
  geom_node_point(size = 5) +
  geom_node_text(aes(label = country), repel = TRUE) +
  coord_fixed()

1.14 geom_arrow_segement

Package

ggarrow (van den Brand 2025)

Description

Draws a straight arrow between points (x, y) and (xend, yend).

Aesthetics

Type Aesthetics
Required x, y, xend or yend
Other supported aesthetics alpha, arrow_fins, arrow_head, arrow_mid
linewidth_fins, linewidth_head, resect_fins, resect_head

See also

geom_line, geom_ribbon, geom_area

Example

library(ggarrow)
worldbankdata |>
  filter(Country == "Bangladesh") |>
  filter(Year >= 2013 & Year <= 2021) |>
  ggplot(aes(x = Year,y=0, yend = Electricity)) +
  geom_arrow_segment() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
  scale_x_continuous(breaks = 2013:2021)

1.15 geom_arrow_curve

Example

data <- data.frame(x = 4, y = 10, xend = 8, yend = 15)
ggplot(data) + 
  geom_arrow_curve(aes(x = x, y = y, xend = xend, yend = yend))

ggplot(data) + 
  geom_arrow_curve(aes(x = x, y = y, xend = xend, yend = yend),
              colour = "red",
              linewidth = 5,
              angle = 90, 
              alpha = 0.2,
              lineend = "butt",
              curvature = -0.5)