15  geom_m

15.1 geom_mark_circle

Package

ggforce (Pedersen 2022)

Description

Annotate sets of points via circles.

Understandable aesthetics

required aesthetics

x

y

optional aesthetics

x0 (used to anchor the label), y0 (used to anchor the label), filter, label, description, color, fill, group, size, linetype, alpha

See also

geom_circle, geom_encircle, geom_mark_ellipse, geom_mark_hull, geom_mark_rect

Example

library(ggforce)
worldbankdata |>
  filter(Country == "Angola") |>
  ggplot(aes(x = Cooking, y=Electricity)) +
  geom_mark_circle(aes(fill = Income, label = Income),
                   con.cap = 0) +
  geom_point(aes(col=Income))

15.2 geom_make_ellipse

Package

ggforce (Pedersen 2022)

Description

Annotate sets of points via ellipse.

Understandable aesthetics

required aesthetics

x

y

optional aesthetics

x0 (used to anchor the label), y0 (used to anchor the label), filter, label, description, color, fill, group, size, linetype, alpha

See also

geom_circle, geom_encircle, geom_mark_circle, geom_mark_hull, geom_mark_rect

Example

library(ggforce)
worldbankdata |>
  filter(Country == "Angola") |>
  ggplot(aes(x = Cooking, y=Electricity)) +
  geom_mark_ellipse(aes(fill = Income, label = Income),
                   con.cap = 0) +
  geom_point(aes(col=Income))

15.3 geom_make_hull

Package

ggforce (Pedersen 2022)

Description

Annotate sets of points via hulls.

Understandable aesthetics

required aesthetics

x

y

optional aesthetics

x0 (used to anchor the label), y0 (used to anchor the label), filter, label, description, color, fill, group, size, linetype, alpha

See also

geom_circle, geom_encircle, geom_mark_circle, geom_mark_ellipse, geom_mark_rect

Example

library(ggforce)
library(concaveman)
worldbankdata |>
  filter(Income == "L" | Income =="UM") |>
  filter(Year == 2021) |>
  ggplot(aes(x = Cooking, y=Electricity)) +
  geom_mark_hull(aes(fill=Income, lable = Income)) +
  geom_point(aes(col=Income))

15.4 geom_make_rect

Package

ggforce (Pedersen 2022)

Description

Annotate sets of points via rectangles.

Understandable aesthetics

required aesthetics

x

y

optional aesthetics

x0 (used to anchor the label), y0 (used to anchor the label), filter, label, description, color, fill, group, size, linetype, alpha

See also

geom_circle, geom_encircle, geom_mark_circle, geom_mark_ellipse, geom_mark_hull

Example

library(ggforce)
worldbankdata |>
  filter(Country == "Angola") |>
  ggplot(aes(x = Cooking, y=Electricity)) +
  geom_mark_rect(aes(fill = Income, label = Income),
                   con.cap = 0) +
  geom_point(aes(col=Income))

15.5 geom_map

Package

ggplot2 (Wickham 2016)

Description

Display polygons as a map.

Understandable aesthetics

required aesthetics

map_id

**optional aesthetics*

alpha, colour, fill ,group, linetype, linewidth, subgropu

See also

geom_polygon

Example

world = map_data("world")
ggplot() +
  geom_map(
    data = world, map = world,
    aes(long, lat, map_id = region),
    fill = "white", colour = "#7f7f7f", size=0.5) 

15.6 geom_mosaic

Package

ggmosaic (Jeppson, Hofmann, and Cook 2021)

Description

Create mosaic plot

Understandable aesthetics

x, y, xmin, xmax, ymin, ymax

See also

geom_bar, geom_mosaic_jitter, geom_mosaic_text

Example

library(ggmosaic)
worldbankdata |>
  filter(Year == 2022) |>
  ggplot() +
  geom_mosaic(aes(x = product(Region), fill = Income)) + 
  scale_fill_brewer(palette = "Dark2") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) 

15.7 geom_mosic_jitter{#mosaic jitter}

Package

ggmosaic (Jeppson, Hofmann, and Cook 2021)

Description

Create a mosaic plot with text or labels.

15.7.1 Understandable aesthetics

x, y, xmin, xmax, ymin, ymax

See also

geom_bar, geom_mosaic, geom_mosaic_text

Example

library(ggmosaic)
worldbankdata |>
  filter(Year == 2022) |>
  ggplot() +
  geom_mosaic(aes(x = product(Region), fill = Income), alpha=0.5) +
  geom_mosaic_text(aes(x = product(Region), fill = Income)) +
  scale_fill_brewer(palette = "Dark2") + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) 

Jeppson, Haley, Heike Hofmann, and Di Cook. 2021. Ggmosaic: Mosaic Plots in the ’Ggplot2’ Framework. https://CRAN.R-project.org/package=ggmosaic.
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.