Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rectangle_key_glyph

Create customizable legend key glyphs


Description

These functions create customizable legend key glyphs, such as filled rectangles or circles.

Usage

rectangle_key_glyph(
  colour = NA,
  fill = fill,
  alpha = alpha,
  size = size,
  linetype = linetype,
  padding = unit(c(0, 0, 0, 0), "pt"),
  color
)

circle_key_glyph(
  colour = NA,
  fill = fill,
  alpha = alpha,
  size = size,
  linetype = linetype,
  padding = unit(c(0, 0, 0, 0), "pt"),
  color
)

Arguments

colour, color

Unquoted name of the aesthetic to use for the outline color, usually colour, color, or fill. Can also be a color constant, e.g. "red".

fill

Unquoted name of the aesthetic to use for the fill color, usually colour, color, or fill. Can also be a color constant, e.g. "red".

alpha

Unquoted name of the aesthetic to use for alpha, usually alpha. Can also be a numerical constant, e.g. 0.5.

size

Unquoted name of the aesthetic to use for the line thickness of the outline, usually size. Can also be a numerical constant, e.g. 0.5.

linetype

Unquoted name of the aesthetic to use for the line type of the outline, usually linetype. Can also be a constant, e.g. 2.

padding

Unit vector with four elements specifying the top, right, bottom, and left padding from the edges of the legend key to the edges of the key glyph.

Examples

library(ggplot2)

set.seed(1233)
df <- data.frame(
  x = sample(letters[1:2], 10, TRUE),
  y = rnorm(10)
)

ggplot(df, aes(x, y, color = x)) +
  geom_boxplot(
    key_glyph = rectangle_key_glyph(fill = color, padding = margin(3, 3, 3, 3))
  )

ggplot(df, aes(x, y, color = x)) +
  geom_boxplot(
    key_glyph = circle_key_glyph(
      fill = color,
      color = "black", linetype = 3, size = 0.3,
      padding = margin(2, 2, 2, 2)
    )
  )

cowplot

Streamlined Plot Theme and Plot Annotations for 'ggplot2'

v1.1.1
GPL-2
Authors
Claus O. Wilke [aut, cre] (<https://orcid.org/0000-0002-7470-9261>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.