scale_fill_pattern {fillpattern}R Documentation

Patterned Fills for ggplot.

Description

Patterned Fills for ggplot.

Usage

scale_fill_pattern(
  patterns = seq_len,
  fg = NA,
  bg = ifelse(is.na(fg), "transparent", NA),
  fade = ifelse(is.na(fg), 1, 0.6),
  alpha = 1,
  angle = 0,
  width = unit(1/10, "npc"),
  height = NA,
  lwd = 1,
  lty = "solid",
  fun = NULL
)

Arguments

patterns

A vector of pattern names that will be subset or recycled as needed to match the levels of the aes() fill variable. If integers are provided, they are mapped to predefined patterns. See "Details and "Pattern Names" sections below. Default: seq_len

fg

Foreground color for the pattern's lines, or NA to use the color scale for the aes() color variable. Default: NA

bg

Background color (or grob), or NA to use the color scale for the aes() color variable. Default: ifelse(is.na(fg), "transparent", NA)

fade, alpha

Modify the color from the aes() color scale. Fade will make it more white, and alpha will make it more transparent. Both values must be between 0 and 1, inclusive, where 1 means unchanged. Default: ⁠fade = ifelse(is.na(fg), 1, 0.6), alpha = 1⁠

angle

How much the rotate the pattern, given in degrees clockwise. Default: 0

width

The width of the pattern tile. Assumed to be millimeters unless set otherwise with unit(). Default: unit(1/10, 'npc')

height

The height of the pattern tile, or NA to match width. Assumed to be millimeters unless set otherwise with unit(). Default: NA

lwd

Line width. A positive number. See graphics::par() for additional details. Default: 1

lty

Line type. One of "solid", "dashed", "dotted", "dotdash", "longdash", or "twodash". See graphics::par() for additional details. Default: "solid"

fun

A function for modifying graphical parameters immediately before rendering. Should accept two parameters: env, an environment that the function should modify, and row, the row of transformed data that ggbuild has constructed for this grob (including aes mappings). The return value is not used. Default: NULL

Details

All of the parameters can accept a vector of values or a function that takes n as an argument and returns the value(s) to use. The values are subset or recycled as needed to obtain the same number as length(levels(fill)), where fill is the variable defined by aes(fill = ).

Value

A ggplot2::discrete_scale() object.

Pattern Names

Base name:

Angle modifier:

Width and height modifier:

Line width and style:

Combinations:

See Also

fill_pattern() for base grid graphics integration.

Examples

 
    library(ggplot2)
    library(fillpattern)
    
    ggplot(mpg, aes(x = class, y = hwy, color = class, fill = class)) +
      geom_boxplot() +
      scale_fill_pattern()

    ggplot(mpg, aes(x = drv, y = hwy, color = drv, fill = drv)) +
      geom_violin() +
      scale_colour_brewer(palette = "Set1") + 
      scale_fill_pattern(c("brick", "stripe45", "grid45_lg"), fg = "black")

    ggplot(mpg, aes(x = drv, color = drv, fill = drv)) +
      geom_bar() +
      scale_fill_pattern(
        patterns = c("hex_sm", "brick90_xl", "fish"),
        lty      = c("solid", "twodash", "dotted"),
        lwd      = c(2, 3, 1) ) +
      theme(legend.key.size = unit(2, 'cm'))
 

[Package fillpattern version 1.0.1 Index]