Skip to contents

The pieglyph geom is used to plot multivariate data as pie glyphs (Ward and Lipchak 2000; Fuchs et al. 2013) in a scatterplot.

Usage

geom_pieglyph(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  cols = character(0L),
  edges = 200,
  fill.segment = NULL,
  fill.gradient = NULL,
  colour.grid = NULL,
  linewidth = 1,
  linewidth.grid = linewidth,
  scale.segment = FALSE,
  scale.radius = TRUE,
  full = TRUE,
  draw.grid = FALSE,
  show.legend = NA,
  repel = FALSE,
  repel.control = gglyph.repel.control(),
  inherit.aes = TRUE
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

stat

The statistical transformation to use on the data for this layer, as a string.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "green" or size = 3. They may also be parameters to the paired geom/stat.

cols

Name of columns specifying the variables to be plotted in the glyphs as a character vector.

edges

The number of edges of the polygon to depict the circular glyph outline.

fill.segment

The fill colour of the segments.

fill.gradient

The palette for gradient fill of the segments. See Details section of col_numeric() function in the scales package for available options.

colour.grid

The colour of grid lines.

linewidth

The line width of the segments.

linewidth.grid

The line width for the grid lines.

scale.segment

logical. If TRUE, the segments (pie slices) are scaled according to value of cols.

scale.radius

logical. If TRUE, the radius of segments (pie slices) are scaled according to value of cols.

full

logical. If TRUE, full star glyphs (360°) are plotted, otherwise half star glyphs (180°) are plotted.

draw.grid

logical. If TRUE, grid points are plotted along the whiskers if all the variables specified in cols are of type factor. Default is FALSE.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

repel

logical. If TRUE, the glyphs are repel away from each other to avoid overlaps. Default is FALSE.

repel.control

A list of control settings for the repel algorithm. Ignored if repel = FALSE. See gglyph.repel.control for details on the various control parameters.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

Value

A geom layer.

Aesthetics

geom_pieglyph() understands the following aesthetics (required aesthetics are in bold):

  • x

  • y

  • alpha

  • colour

  • fill

  • group

  • size

See vignette("ggplot2-specs", package = "ggplot2") for further details on setting these aesthetics.

The following additional aesthetics are considered if repel = TRUE:

  • point.size

  • segment.linetype

  • segment.colour

  • segment.size

  • segment.alpha

  • segment.curvature

  • segment.angle

  • segment.ncp

  • segment.shape

  • segment.square

  • segment.squareShape

  • segment.inflect

  • segment.debug

See ggrepel examples page for further details on setting these aesthetics.

References

Fuchs J, Fischer F, Mansmann F, Bertini E, Isenberg P (2013). “Evaluation of alternative glyph designs for time series data in a small multiple setting.” In Proceedings of the SIGCHI Conference on Human Factors in Computing Systems, 3237--3246. ISBN 978-1-4503-1899-0.

Ward MO, Lipchak BN (2000). “A visualization tool for exploratory analysis of cyclic multivariate data.” Metrika, 51(1), 27--37.

Examples

zs <- c("hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb")
mtcars[ , zs] <- lapply(mtcars[ , zs], scales::rescale)

mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$lab <- row.names(mtcars)

library(ggplot2)
theme_set(theme_bw())
options(ggplot2.discrete.colour = RColorBrewer::brewer.pal(8, "Dark2"))
options(ggplot2.discrete.fill = RColorBrewer::brewer.pal(8, "Dark2"))

# Mapped fill + scaled radius
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, fill = cyl),
                cols = zs, size = 10,
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, fill = cyl),
                cols = zs, size = 10,
                alpha =  0.8, full = FALSE) +
  ylim(c(-0, 550))


# Mapped fill + scaled segment
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, fill = cyl),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = TRUE,
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, fill = cyl),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = TRUE,
                alpha =  0.8, full = FALSE) +
  ylim(c(-0, 550))


# Mapped colour + scaled radius
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 10,
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 10, fill = "white",
                alpha =  0.8,  linewidth = 2) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 10,
                alpha =  0.8, full = FALSE) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 10, fill = "white",
                alpha =  0.8,  linewidth = 2, full = FALSE) +
  ylim(c(-0, 550))


# Mapped colour + scaled segment
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = TRUE,
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 5, fill = "white",
                scale.radius = FALSE, scale.segment = TRUE,
                alpha =  0.8, linewidth = 2) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = TRUE,
                alpha =  0.8, full = FALSE) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 5, fill = "white",
                scale.radius = FALSE, scale.segment = TRUE,
                alpha =  0.8, linewidth = 2, full = FALSE) +
  ylim(c(-0, 550))


# Segments with colours + scaled radius
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 10,
                fill.segment = RColorBrewer::brewer.pal(8, "Dark2"),
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 10,
                fill.segment = RColorBrewer::brewer.pal(8, "Dark2"),
                alpha =  0.8, full = FALSE) +
  ylim(c(-0, 550))


# Segments with colours + scaled segment (scatterpie)
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = TRUE,
                fill.segment = RColorBrewer::brewer.pal(8, "Dark2"),
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = TRUE,
                fill.segment = RColorBrewer::brewer.pal(8, "Dark2"),
                alpha =  0.8, full = FALSE) +
  ylim(c(-0, 550))


# Gradient fill
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = FALSE,
                fill.gradient = "Greens",
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = FALSE,
                fill.gradient = "Blues",
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = FALSE,
                fill.gradient = "RdYlBu",
                alpha =  0.8) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = FALSE,
                fill.gradient = "viridis",
                alpha =  0.8) +
  ylim(c(-0, 550))


# Faceted
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, fill = cyl),
                cols = zs, size = 10,
                alpha =  0.8) +
  ylim(c(-0, 550)) +
  facet_grid(. ~ cyl)


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 10,
                alpha =  0.8) +
  ylim(c(-0, 550)) +
  facet_grid(. ~ cyl)


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 10,
                fill.segment = RColorBrewer::brewer.pal(8, "Dark2"),
                alpha =  0.8) +
  ylim(c(-0, 550)) +
  facet_grid(. ~ cyl)


# Repel glyphs
ggplot(data = mtcars) +
  geom_point(aes(x = mpg, y = disp, colour = cyl)) +
  geom_pieglyph(aes(x = mpg, y = disp, fill = cyl),
                cols = zs, size = 10,
                alpha =  1, repel = TRUE) +
  ylim(c(-0, 550))
#> Warning: 6 glyphs have too many overlaps.
#> Consider increasing "max.overlaps"


ggplot(data = mtcars) +
  geom_point(aes(x = mpg, y = disp, colour = cyl)) +
  geom_pieglyph(aes(x = mpg, y = disp, fill = cyl),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = TRUE,
                alpha =  1, full = FALSE, repel = TRUE) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_point(aes(x = mpg, y = disp, colour = cyl)) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 10,
                alpha =  1, repel = TRUE) +
  ylim(c(-0, 550))
#> Warning: 6 glyphs have too many overlaps.
#> Consider increasing "max.overlaps"


ggplot(data = mtcars) +
  geom_point(aes(x = mpg, y = disp, colour = cyl)) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = TRUE,
                alpha =  1, full = FALSE, repel = TRUE) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_point(aes(x = mpg, y = disp)) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 10,
                fill.segment = RColorBrewer::brewer.pal(8, "Dark2"),
                alpha =  1, repel = TRUE) +
  ylim(c(-0, 550))
#> Warning: 5 glyphs have too many overlaps.
#> Consider increasing "max.overlaps"


ggplot(data = mtcars) +
  geom_point(aes(x = mpg, y = disp)) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 5,
                scale.radius = FALSE, scale.segment = FALSE,
                fill.gradient = "viridis",
                alpha =  1, repel = TRUE) +
  ylim(c(-0, 550))


rm(mtcars)
mtcars[ , zs] <- lapply(mtcars[ , zs], scales::rescale)

mtcars[ , zs] <- lapply(mtcars[, zs],
                        function(x) cut(x, breaks = 3,
                                        labels = c(1, 2, 3)))
mtcars[ , zs] <- lapply(mtcars[ , zs], as.factor)

mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$lab <- row.names(mtcars)

# Grid lines (when scale.radius = TRUE)
ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, fill = cyl),
                cols = zs, size = 2,
                alpha =  0.8, draw.grid = TRUE) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp, colour = cyl),
                cols = zs, size = 2,
                alpha =  0.8, draw.grid = TRUE) +
  ylim(c(-0, 550))


ggplot(data = mtcars) +
  geom_pieglyph(aes(x = mpg, y = disp),
                cols = zs, size = 2,
                scale.radius = TRUE, scale.segment = FALSE,
                fill.gradient = "Blues",
                alpha =  0.8, draw.grid = TRUE) +
  ylim(c(-0, 550))