24  geom_v

24.1 geom_violin

Package

ggplot2 (Wickham 2016)

Description

Creates violin plot.

Understandable aesthetics

required aesthetics

x

y

optional aesthetics

alpha, colour, group, linetype, linewidth, weight

See also

geom_boxplot, geom_density

Example

worldbankdata |>
  dplyr::filter(Year == 2021) |>
ggplot(aes(y = Cooking, x=Income, fill=Income)) + 
  geom_violin() + 
  scale_fill_brewer(palette = "Dark2") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

24.2 geom_violin_pattern

Package

ggforce (Pedersen 2022)

Description

Fill violin plots with patterns.

Understandable aesthetics

required aesthetics

x

y

optional aesthetics

alpha, colour, group, linetype, linewidth, weight

24.2.1 The statistical transformation to use on the data for this layer

ydensity

See also

geom_boxplot, geom_density

Example

worldbankdata |>
  dplyr::filter(Year == 2021) |>
ggplot(aes(y = Cooking, x=Income, fill=Income)) + 
  geom_violin_pattern() + 
  scale_fill_brewer(palette = "Dark2") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

24.3 geom_voronoi_tile

Package

ggforce (Pedersen 2022)

Description

Voronoi tiles are the polygons that result from the spatial division of a plane based on the input points.

Understandable aesthetics

required aesthetics

x

y

optional aesthetics

alpha, colour, linetype, size

See also

geom_voronoi_segment, geom_delaunay_tile, geom_delaunay_segment

Example

library(ggforce)
a1 <- worldbankdata |>
  filter(Income == "L") |>
  filter(Region == "Middle East & North Africa" | Region == "Sub-Saharan Africa") |>
  ggplot(aes(x=Cooking, y=Electricity)) +   
  geom_voronoi_tile(alpha=0.5, aes(fill=Region)) + 
  labs(title = "a1: geom_voronoi_tile only") +
  scale_fill_brewer(palette = "Dark2") +
  scale_color_brewer(palette = "Dark2") +
  theme(aspect.ratio = 1) + 
  theme(legend.position='bottom')
a2 <- worldbankdata |>
  filter(Income == "L") |>
  filter(Region == "Middle East & North Africa" | Region == "Sub-Saharan Africa") |>
  ggplot(aes(x=Cooking, y=Electricity)) +   
  geom_voronoi_tile(alpha=0.5, aes(fill=Region)) + 
  geom_point(aes(col=Region)) + 
  labs(title = "a1: geom_voronoi_tile and  geom_point") +
  scale_fill_brewer(palette = "Dark2") +
  scale_color_brewer(palette = "Dark2") +
  theme(aspect.ratio = 1) +
  theme(legend.position='none')
a1|a2

24.4 geom_voronoi_segment

Package

ggforce (Pedersen 2022)

Description

Represents the borders between the regions assigned to different input points.

Understandable aesthetics

required aesthetics

x

y

optional aesthetics

alpha, colour, linetype, size

See also

geom_voronoi_tile, geom_delaunay_tile, geom_delaunay_segment

Example

library(ggforce)
library(deldir) #to calculate delaunay triangulation
a1 <- worldbankdata |>
  filter(Year == 2021) |>
  filter(Income == "LM" | Income == "UM") |>
  ggplot(aes(x=Cooking, y=Electricity)) +   
  geom_voronoi_segment() +
  labs(title = "a1: geom_voronoi_segment only") +
  theme(aspect.ratio = 1)

a2 <- worldbankdata |>
  filter(Year == 2021) |>
  filter(Income == "LM" | Income == "UM") |>
  ggplot(aes(x=Cooking, y=Electricity)) +   
  geom_point() +
  geom_voronoi_segment() +
  labs(title = "a2: geom_point and \n geom_voronoi_segment") +
  theme(aspect.ratio = 1)
a1 | a2

Pedersen, Thomas Lin. 2022. Ggforce: Accelerating ’Ggplot2’. https://CRAN.R-project.org/package=ggforce.
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.