Supported Plot Types

The following plot types are supported.

Any ggplot2 geom is supported, but we added support for some other, more advanced plots.

Column / Bar

Used for comparing discrete categories through rectangular bars.

diamonds |> # from the ggplot2 package
  plot2(x = cut,
        y = n())

In plot2, bar types are horizontal alternatives for column types (just like MS Excel):

diamonds |>
  plot2(x = cut,
        y = n(),
        type = "bar")

Line

Used for visualising trends over ordered intervals.

pressure |> # from base R
  plot2(x = temperature,
        y = pressure,
        type = "line")

pressure |>
  plot2(x = temperature,
        y = pressure,
        type = "line-point")

Point

Used for displaying individual observations in a two dimensional space.

iris |> # from base R
  plot2()

diamonds |>
  plot2(x = carat,
        y = price,
        category = cut,
        type = "point")

Area

Used for emphasising cumulative magnitudes across continuous domains.

pressure |>
  plot2(x = temperature,
        y = pressure,
        type = "area")

airquality |>
  plot2(x = Day, 
        y = Wind, 
        category = Month,
        category.character = TRUE,
        stacked_fill= TRUE,
        type = "area")

Boxplot / Violin

Used for summarising and comparing distributions with focus on spread and density.

iris |>
  plot2(x = Species,
        type = "violin")

iris |>
  plot2(x = Species,
        y = where(is.double),
        type = "boxplot")

Histogram

Used for visualising the frequency distribution of continuous variables.

diamonds |>
  plot2(x = price,
        type = "hist")

Geo (sf)

Used for mapping spatial data encoded as simple features.

netherlands |> # from this plot2 package
  plot2()

Beeswarm

Used for showing distributions of individual observations without overlap.

iris |>
  plot2(x = Species,
        y = Sepal.Length,
        type = "beeswarm")

Back-to-back

Used for contrasting two mirrored groups across shared categories.

admitted_patients |> # from this plot2 package
  plot2(x = age_group,
        y = n(),
        facet = ward,
        type = "back-to-back")

admitted_patients |> # from this plot2 package
  plot2(x = age_group,
        y = n(),
        y.limits = c(0, 60),
        category = gender,
        facet = ward,
        type = "back-to-back")

Sankey

Used for depicting flows or transitions between connected stages.

Titanic |> # from base R
  plot2(x = c(Age, Class, Survived),
        category = Sex,
        type = "sankey")

Spider

Used for comparing multivariate values across categorical axes arranged radially, enabling pattern recognition and relative magnitude assessment between groups.

diamonds |>
    plot2(x = cut,
          y = mean(price),
          category = color,
          type = "spider",
          y.labels = dollars)

# spider plots can have a filling colour, but it's hardly ever useful
diamonds |>
    plot2(x = cut,
          y = mean(price),
          category = color,
          type = "spider",
          y.labels = dollars,
          colour_fill = "viridis")

UpSet

Used for analysing intersections among multiple sets with scalable clarity.

movies |> # from the ggplot2movies package
  plot2(x = c(Action, Animation, Comedy, Drama, Romance),
        type = "upset")

movies |>
  plot2(x = c(Action, Animation, Comedy, Drama, Romance),
        y = median(rating),
        y.title = "Median Rating",
        x.sort = TRUE,
        type = "upset")

Dumbbell

Used for highlighting changes or differences between paired values.

diamonds |>
  dplyr::filter(cut %in% c("Fair", "Very Good")) |>
  plot2(x = cut(carat, 6),
        y = median(price),
        category = cut,
        type = "dumbbell")

  • true