| Title: | 'ggplot2' Pattern Geoms |
|---|---|
| Description: | Provides 'ggplot2' geoms filled with various patterns. Includes a patterned version of every 'ggplot2' geom that has a region that can be filled with a pattern. Provides a suite of 'ggplot2' aesthetics and scales for controlling pattern appearances. Supports over a dozen builtin patterns (every pattern implemented by 'gridpattern') as well as allowing custom user-defined patterns. |
| Authors: | Mike FC [aut], Trevor L. Davis [aut, cre] (ORCID: <https://orcid.org/0000-0001-6341-4639>), ggplot2 authors [aut] |
| Maintainer: | Trevor L. Davis <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.4.0-7 |
| Built: | 2026-11-22 23:50:01 UTC |
| Source: | https://github.com/trevorld/ggpattern |
default_pattern_aes() returns the default values of the pattern aesthetics
(e.g. pattern and pattern_fill) for the default_aes of a pattern geom.
Most are NaN which means "unset":
the pattern's own (registered) default applies (or else {gridpattern}'s generic default)
unlike NA which may be meaningful (e.g. a transparent colour).
The only exception is pattern which defaults to "stripe".
default_pattern_aes()default_pattern_aes()
A ggplot2::aes() mapping of constant values.
make_GeomPattern() which adds them to a geom's default_aes for you.
See vignette("developing-pattern-geoms", package = "ggpattern") for writing a pattern geom.
names(default_pattern_aes()) # e.g. for the `default_aes` of a pattern geom made from `ggplot2::GeomSmooth` default_aes <- ggplot2::aes(!!!ggplot2::GeomSmooth$default_aes, !!!default_pattern_aes())names(default_pattern_aes()) # e.g. for the `default_aes` of a pattern geom made from `ggplot2::GeomSmooth` default_aes <- ggplot2::aes(!!!ggplot2::GeomSmooth$default_aes, !!!default_pattern_aes())
Each geom has an associated function that draws the key when the geom needs
to be displayed in a legend. These functions are called draw_key_*(), where
* stands for the name of the respective key glyph. The key glyphs can be
customized for individual geoms by providing a geom with the key_glyph
argument (see ggplot2::layer() or examples below.)
draw_key_polygon_pattern(data, params, size, aspect_ratio = get_aspect_ratio()) draw_key_boxplot_pattern(data, params, size, aspect_ratio = get_aspect_ratio()) draw_key_crossbar_pattern( data, params, size, aspect_ratio = get_aspect_ratio() ) draw_key_point_pattern(data, params, size, aspect_ratio = get_aspect_ratio())draw_key_polygon_pattern(data, params, size, aspect_ratio = get_aspect_ratio()) draw_key_boxplot_pattern(data, params, size, aspect_ratio = get_aspect_ratio()) draw_key_crossbar_pattern( data, params, size, aspect_ratio = get_aspect_ratio() ) draw_key_point_pattern(data, params, size, aspect_ratio = get_aspect_ratio())
data |
A single row data frame containing the scaled aesthetics to display in this key |
params |
A list of additional parameters supplied to the geom. |
size |
Width and height of key in mm. |
aspect_ratio |
the geom's best guess at what the aspect ratio might be. |
A grid grob.
if (require("ggplot2")) { # 'stripe' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black', key_glyph = draw_key_polygon_pattern ) + theme_bw(18) + theme(legend.position = 'none') + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'stripe'" ) plot(gg) }if (require("ggplot2")) { # 'stripe' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black', key_glyph = draw_key_polygon_pattern ) + theme_bw(18) + theme(legend.position = 'none') + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'stripe'" ) plot(gg) }
All geoms in this package are identical to their counterparts in ggplot2 except that they can be filled with patterns.
geom_rect_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_bar_pattern( mapping = NULL, data = NULL, stat = "count", position = "stack", ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_tile_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_bin_2d_pattern( mapping = NULL, data = NULL, stat = "bin2d", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_bin2d_pattern( mapping = NULL, data = NULL, stat = "bin2d", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_boxplot_pattern( mapping = NULL, data = NULL, stat = "boxplot", position = "dodge2", ..., outliers = TRUE, outlier.colour = NULL, outlier.color = NULL, outlier.fill = NULL, outlier.shape = NULL, outlier.size = NULL, outlier.stroke = 0.5, outlier.alpha = NULL, whisker.colour = NULL, whisker.color = NULL, whisker.linetype = NULL, whisker.linewidth = NULL, staple.colour = NULL, staple.color = NULL, staple.linetype = NULL, staple.linewidth = NULL, median.colour = NULL, median.color = NULL, median.linetype = NULL, median.linewidth = NULL, box.colour = NULL, box.color = NULL, box.linetype = NULL, box.linewidth = NULL, notch = FALSE, notchwidth = 0.5, staplewidth = 0, varwidth = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) geom_col_pattern( mapping = NULL, data = NULL, stat = "identity", position = "stack", ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_polygon_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., rule = "evenodd", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_contour_filled_pattern( mapping = NULL, data = NULL, stat = "contour_filled", position = "identity", ..., bins = NULL, binwidth = NULL, breaks = NULL, rule = "evenodd", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_crossbar_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., middle.colour = NULL, middle.color = NULL, middle.linetype = NULL, middle.linewidth = NULL, box.colour = NULL, box.color = NULL, box.linetype = NULL, box.linewidth = NULL, fatten = deprecated(), na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) geom_ribbon_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., orientation = NA, lineend = "butt", linejoin = "round", linemitre = 10, outline.type = "both", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_area_pattern( mapping = NULL, data = NULL, stat = "align", position = "stack", ..., orientation = NA, outline.type = "upper", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_density_pattern( mapping = NULL, data = NULL, stat = "density", position = "identity", ..., outline.type = "upper", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_density_2d_filled_pattern( mapping = NULL, data = NULL, stat = "density_2d_filled", position = "identity", ..., contour_var = "density", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_density2d_filled_pattern( mapping = NULL, data = NULL, stat = "density_2d_filled", position = "identity", ..., contour_var = "density", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_dotplot_pattern( mapping = NULL, data = NULL, position = "identity", ..., binwidth = NULL, binaxis = "x", method = "dotdensity", binpositions = "bygroup", stackdir = "up", stackratio = 1, dotsize = 1, stackgroups = FALSE, origin = NULL, right = TRUE, width = 0.9, drop = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_hex_pattern( mapping = NULL, data = NULL, stat = "binhex", position = "identity", ..., lineend = "butt", linejoin = "mitre", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_histogram_pattern( mapping = NULL, data = NULL, stat = "bin", position = "stack", ..., binwidth = NULL, bins = NULL, orientation = NA, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_map_pattern( mapping = NULL, data = NULL, stat = "identity", ..., map, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_point_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_sf_pattern( mapping = aes(), data = NULL, stat = "sf", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) geom_violin_pattern( mapping = NULL, data = NULL, stat = "ydensity", position = "dodge", ..., trim = TRUE, bounds = c(-Inf, Inf), quantile.colour = NULL, quantile.color = NULL, quantile.linetype = 0L, quantile.linewidth = NULL, draw_quantiles = deprecated(), scale = "area", na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )geom_rect_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_bar_pattern( mapping = NULL, data = NULL, stat = "count", position = "stack", ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_tile_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_bin_2d_pattern( mapping = NULL, data = NULL, stat = "bin2d", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_bin2d_pattern( mapping = NULL, data = NULL, stat = "bin2d", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_boxplot_pattern( mapping = NULL, data = NULL, stat = "boxplot", position = "dodge2", ..., outliers = TRUE, outlier.colour = NULL, outlier.color = NULL, outlier.fill = NULL, outlier.shape = NULL, outlier.size = NULL, outlier.stroke = 0.5, outlier.alpha = NULL, whisker.colour = NULL, whisker.color = NULL, whisker.linetype = NULL, whisker.linewidth = NULL, staple.colour = NULL, staple.color = NULL, staple.linetype = NULL, staple.linewidth = NULL, median.colour = NULL, median.color = NULL, median.linetype = NULL, median.linewidth = NULL, box.colour = NULL, box.color = NULL, box.linetype = NULL, box.linewidth = NULL, notch = FALSE, notchwidth = 0.5, staplewidth = 0, varwidth = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) geom_col_pattern( mapping = NULL, data = NULL, stat = "identity", position = "stack", ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_polygon_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., rule = "evenodd", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_contour_filled_pattern( mapping = NULL, data = NULL, stat = "contour_filled", position = "identity", ..., bins = NULL, binwidth = NULL, breaks = NULL, rule = "evenodd", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_crossbar_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., middle.colour = NULL, middle.color = NULL, middle.linetype = NULL, middle.linewidth = NULL, box.colour = NULL, box.color = NULL, box.linetype = NULL, box.linewidth = NULL, fatten = deprecated(), na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) geom_ribbon_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., orientation = NA, lineend = "butt", linejoin = "round", linemitre = 10, outline.type = "both", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_area_pattern( mapping = NULL, data = NULL, stat = "align", position = "stack", ..., orientation = NA, outline.type = "upper", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_density_pattern( mapping = NULL, data = NULL, stat = "density", position = "identity", ..., outline.type = "upper", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_density_2d_filled_pattern( mapping = NULL, data = NULL, stat = "density_2d_filled", position = "identity", ..., contour_var = "density", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_density2d_filled_pattern( mapping = NULL, data = NULL, stat = "density_2d_filled", position = "identity", ..., contour_var = "density", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_dotplot_pattern( mapping = NULL, data = NULL, position = "identity", ..., binwidth = NULL, binaxis = "x", method = "dotdensity", binpositions = "bygroup", stackdir = "up", stackratio = 1, dotsize = 1, stackgroups = FALSE, origin = NULL, right = TRUE, width = 0.9, drop = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_hex_pattern( mapping = NULL, data = NULL, stat = "binhex", position = "identity", ..., lineend = "butt", linejoin = "mitre", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_histogram_pattern( mapping = NULL, data = NULL, stat = "bin", position = "stack", ..., binwidth = NULL, bins = NULL, orientation = NA, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_map_pattern( mapping = NULL, data = NULL, stat = "identity", ..., map, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_point_pattern( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_sf_pattern( mapping = aes(), data = NULL, stat = "sf", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) geom_violin_pattern( mapping = NULL, data = NULL, stat = "ydensity", position = "dodge", ..., trim = TRUE, bounds = c(-Inf, Inf), quantile.colour = NULL, quantile.color = NULL, quantile.linetype = 0L, quantile.linewidth = NULL, draw_quantiles = deprecated(), scale = "area", na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
just |
Adjustment for column placement. Set to |
outliers |
Whether to display ( |
outlier.colour, outlier.color, outlier.fill, outlier.shape, outlier.size, outlier.stroke, outlier.alpha
|
Default aesthetics for outliers. Set to |
whisker.colour, whisker.color, whisker.linetype, whisker.linewidth
|
Default aesthetics for the whiskers. Set to |
staple.colour, staple.color, staple.linetype, staple.linewidth
|
Default aesthetics for the staples. Set to |
median.colour, median.color, median.linetype, median.linewidth
|
Default aesthetics for the median line. Set to |
box.colour, box.color, box.linetype, box.linewidth
|
Default aesthetics for the boxes. Set to |
notch |
If |
notchwidth |
For a notched box plot, width of the notch relative to
the body (defaults to |
staplewidth |
The relative width of staples to the width of the box. Staples mark the ends of the whiskers with a line. |
varwidth |
If |
orientation |
The orientation of the layer. The default ( |
rule |
Either |
linemitre |
Line mitre limit (number greater than 1). |
bins |
For |
binwidth |
For |
breaks |
For |
middle.colour, middle.color, middle.linetype, middle.linewidth
|
Default aesthetics for the middle line. Set to |
fatten |
|
outline.type |
Type of the outline of the area; |
contour_var |
Character string identifying the variable to contour
by. Can be one of |
binaxis |
The axis to bin along, "x" (default) or "y" |
method |
"dotdensity" (default) for dot-density binning, or "histodot" for fixed bin widths (like stat_bin) |
binpositions |
When |
stackdir |
which direction to stack the dots. "up" (default), "down", "center", "centerwhole" (centered, but with dots aligned) |
stackratio |
how close to stack the dots. Default is 1, where dots just touch. Use smaller values for closer, overlapping dots. |
dotsize |
The diameter of the dots relative to |
stackgroups |
should dots be stacked across groups? This has the effect
that |
origin |
When |
right |
When |
width |
When |
drop |
Treatment of zero count bins. If |
map |
Data frame that contains the map coordinates. This will
typically be created using |
trim |
If |
bounds |
Known lower and upper bounds for estimated data. Default
|
quantile.colour, quantile.color, quantile.linewidth, quantile.linetype
|
Default aesthetics for the quantile lines. Set to |
draw_quantiles |
|
scale |
if "area" (default), all violins have the same area (before trimming the tails). If "count", areas are scaled proportionally to the number of observations. If "width", all violins have the same maximum width. |
geom_point_pattern() fills each point with a filled symbol (shape 21 to 25, its default is 21)
with its own pattern (e.g. a different image per point) and requires R (>= 4.2.0).
Points with other shapes are drawn as by ggplot2::geom_point().
Pattern lengths (e.g. pattern_spacing) are relative to the plot panel by default
so for finer geometry patterns within (small) points use an absolute unit
e.g. pattern_units = "mm" with a small pattern_spacing.
geom_dotplot_pattern() fills each dot with its own pattern and requires R (>= 4.2.0).
Like ggplot2::geom_dotplot() its default fill is the theme's ink colour.
geom_hex_pattern() requires the suggested package {hexbin}.
A ggplot2::Geom object.
Not all arguments apply to all patterns.
Most pattern aesthetics default to the pattern's own default
(see the documentation of the corresponding gridpattern::grid.pattern_<name>() function)
which for most patterns is {gridpattern}'s generic default (listed below as "generic").
Internally these unset aesthetics have the value NaN, which {gridpattern} treats as unset
(whereas NA may be meaningful e.g. a transparent colour or a "pch" shape that draws nothing).
patternPattern name string e.g. 'stripe' (default), 'crosshatch', 'point', 'circle', 'none'
pattern_alpha Alpha transparency for pattern. default: pattern default (generic: NA i.e. keep the colours' alpha)
pattern_angleOrientation of the pattern in degrees. default: pattern default (generic: 30)
pattern_aspect_ratioAspect ratio adjustment. default: the aspect ratio of the plot panel / legend key
pattern_colourColour used for strokes and points. default: pattern default (generic: 'grey20')
pattern_densityApproximate fill fraction of the pattern. Usually in range [0, 1], but can be higher. default: pattern default (generic: 0.2)
pattern_filenameImage filename/URL. default: pattern default (generic: ”)
pattern_fill Fill colour (or grid::pattern()/gradient fill). default: pattern default (generic: 'grey80')
pattern_fill2 Second fill colour (or grid::pattern()/gradient fill). default: pattern default (generic: '#4169E1')
pattern_filter(Image scaling) filter. default: pattern default (generic: 'lanczos')
pattern_frequencyFrequency. default: pattern default (generic: 0.1)
pattern_gravityImage placement. default: pattern default (generic: 'center')
pattern_gridPattern grid type. default: pattern default (generic: 'square')
pattern_key_scale_factorZoom factor for the pattern in the legend key (multiplies the size of relative i.e. 'snpc' lengths relative to the key as well as the spacing and offsets of absolute lengths). default: 1
pattern_linetypeStroke linetype. default: pattern default (generic: 1)
pattern_linewidth Stroke line width. default: pattern default (generic: pattern_size if set else 0.5)
pattern_option_1Generic user value for custom patterns. default: pattern default (generic: 0)
pattern_option_2Generic user value for custom patterns. default: pattern default (generic: 0)
pattern_option_3Generic user value for custom patterns. default: pattern default (generic: 0)
pattern_option_4Generic user value for custom patterns. default: pattern default (generic: 0)
pattern_option_5Generic user value for custom patterns. default: pattern default (generic: 0)
pattern_orientation'vertical', 'horizontal', or 'radial'. default: pattern default (generic: 'vertical')
pattern_phasePhase (generic user value for custom patterns). default: pattern default (generic: 0)
pattern_res Pattern resolution (pixels per inch). default: getOption("ggpattern_res") if set else slightly above the device resolution (72 ppi for vector devices such as PDF/SVG); legend keys use a higher resolution so that pixel-based patterns look like they do in the plot
pattern_rotRotation angle (shape within pattern). default: pattern default (generic: 0)
pattern_scaleScale. default: pattern default (generic: 1)
pattern_shapePlotting shape. default: pattern default (generic: 1)
pattern_size Fontsize ("text" pattern) or legacy stroke line width (superseded by pattern_linewidth). default: pattern default (generic: 0.5)
pattern_spacingSpacing of the pattern as a fraction of the plot size. default: pattern default (generic: 0.05)
pattern_type Generic control option. default: pattern default (generic: NA)
pattern_subtype Generic control option. default: pattern default (generic: NA)
pattern_xoffsetOffset the origin of the pattern. Range [0, 1]. default: pattern default (generic: 0). Use this to slightly shift the origin of the pattern. For most patterns, the user should limit the offset value to be less than the pattern spacing.
pattern_yoffsetOffset the origin of the pattern. Range [0, 1]. default: pattern default (generic: 0). Use this to slightly shift the origin of the pattern. For most patterns, the user should limit the offset value to be less than the pattern spacing.
if (require("ggplot2")) { # 'stripe' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'stripe'" ) plot(gg) # 'pch' pattern example gg <- ggplot(mtcars, aes(as.factor(cyl), mpg)) + geom_violin_pattern(aes(fill = as.factor(cyl), pattern_shape = as.factor(cyl)), pattern = 'pch', pattern_density = 0.3, pattern_angle = 0, colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + labs( title = "ggpattern::geom_violin_pattern()", subtitle = "pattern = 'pch'" ) plot(gg) # 'polygon_tiling' pattern example gg <- ggplot(mtcars) + geom_density_pattern( aes( x = mpg, pattern_fill = as.factor(cyl), pattern_type = as.factor(cyl) ), pattern = 'polygon_tiling', pattern_key_scale_factor = 1.2 ) + scale_pattern_type_manual(values = c("hexagonal", "rhombille", "pythagorean")) + theme_bw(18) + theme(legend.key.size = unit(2, 'cm')) + labs( title = "ggpattern::geom_density_pattern()", subtitle = "pattern = 'polygon_tiling'" ) plot(gg) }if (require("ggplot2")) { # 'stripe' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'stripe'" ) plot(gg) # 'pch' pattern example gg <- ggplot(mtcars, aes(as.factor(cyl), mpg)) + geom_violin_pattern(aes(fill = as.factor(cyl), pattern_shape = as.factor(cyl)), pattern = 'pch', pattern_density = 0.3, pattern_angle = 0, colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + labs( title = "ggpattern::geom_violin_pattern()", subtitle = "pattern = 'pch'" ) plot(gg) # 'polygon_tiling' pattern example gg <- ggplot(mtcars) + geom_density_pattern( aes( x = mpg, pattern_fill = as.factor(cyl), pattern_type = as.factor(cyl) ), pattern = 'polygon_tiling', pattern_key_scale_factor = 1.2 ) + scale_pattern_type_manual(values = c("hexagonal", "rhombille", "pythagorean")) + theme_bw(18) + theme(legend.key.size = unit(2, 'cm')) + labs( title = "ggpattern::geom_density_pattern()", subtitle = "pattern = 'polygon_tiling'" ) plot(gg) }
Geom ggproto objects that could be extended to create a new geom.
Each of these extends a {ggplot2} geom, either directly (e.g. GeomRectPattern extends ggplot2::GeomRect)
or through another of these (e.g. GeomColPattern extends GeomBarPattern which extends GeomRectPattern),
and uses the methods (e.g. the draw method) of the {ggplot2} that is loaded.
However, a few things are copied from {ggplot2} when {ggpattern} is installed:
The default aesthetics of GeomDotplotPattern, GeomHexPattern, GeomPointPattern, and GeomSfPattern
are those of their {ggplot2} geom (plus the pattern aesthetics).
The arguments of the geom_*_pattern() functions made by ggplot2::make_constructor()
(e.g. geom_hex_pattern()) are those of the geom and stat's parameters.
So after upgrading {ggplot2} you can reinstall {ggpattern} from source
(e.g. install.packages("ggpattern", type = "source")) to pick up any new default aesthetics or arguments
(a binary package has those of the {ggplot2} it was built with).
make_geom_pattern() makes a geom_*_pattern() function
from a geom_*() function (e.g. ggplot2::geom_smooth) or from a geom (e.g. ggridges::GeomDensityRidges).
Prefer giving it the geom_*() function if there is one.
make_geom_pattern(x, ...) ## S3 method for class ''function'' make_geom_pattern(x, ..., area_by = NULL) ## S3 method for class 'Geom' make_geom_pattern(x, ..., area_by = NULL, env = caller_env())make_geom_pattern(x, ...) ## S3 method for class ''function'' make_geom_pattern(x, ..., area_by = NULL) ## S3 method for class 'Geom' make_geom_pattern(x, ..., area_by = NULL, env = caller_env())
x |
A function that returns a layer (or a list of layers and other |
... |
For a function must be empty.
For a geom passed on to |
area_by |
How the areas the geom draws are matched to the rows of its data,
see |
env |
For a geom the |
Given a function it returns a function which calls x and then with_pattern() on what it returns
so it keeps the stat, position, and every other default (and check) of x.
Its arguments are mapping and ...:
the pattern aesthetics among them (set to a constant in ... or mapped in mapping)
are held back for with_pattern() and all of the others are passed on to x
(mapping by name if x has an argument of that name or else as its first argument).
The pattern geom is made each time the function is called
so (unlike a geom made by make_GeomPattern()) it always uses the installed version of the geom.
Given a geom it returns the function made by ggplot2::make_constructor()
for the pattern geom made by make_GeomPattern()
(our own pattern geom if x is a {ggplot2} geom we have one for or x itself if it already is a pattern geom).
A geom doesn't know the defaults of its geom_*() function
so its stat and position (if they aren't "identity")
and any other argument whose default differs from that of the geom's draw method
must be given in ...
e.g. stat = ggridges::StatDensityRidges, position = ggridges::position_points_sina()
for ggridges::GeomDensityRidges.
Some defaults can't be given this way
e.g. ggplot2::geom_smooth() in the development version of {ggplot2} hides the outline of its confidence band
which a pattern geom made from ggplot2::GeomSmooth would draw.
The function stores the pattern geom (see the note on packages in make_GeomPattern()).
A function that returns a layer
(or whatever x returns with its layers made pattern layers).
with_pattern() to make a pattern layer from a layer
and make_GeomPattern() to make a pattern geom from a geom.
library("ggplot2") geom_smooth_pattern <- make_geom_pattern(geom_smooth) ggplot(mtcars, aes(mpg, wt)) + geom_point() + geom_smooth_pattern(aes(pattern = factor(am)), method = "lm", formula = y ~ x, pattern_colour = "grey40", pattern_spacing = 0.03) # from a geom: we must give the defaults of its `geom_*()` function ourselves if (requireNamespace("ggridges", quietly = TRUE)) { geom_density_ridges_pattern <- make_geom_pattern(ggridges::GeomDensityRidges, stat = ggridges::StatDensityRidges, position = ggridges::position_points_sina()) ggplot(iris, aes(Sepal.Length, Species, pattern = Species)) + geom_density_ridges_pattern(pattern_spacing = 0.03) }library("ggplot2") geom_smooth_pattern <- make_geom_pattern(geom_smooth) ggplot(mtcars, aes(mpg, wt)) + geom_point() + geom_smooth_pattern(aes(pattern = factor(am)), method = "lm", formula = y ~ x, pattern_colour = "grey40", pattern_spacing = 0.03) # from a geom: we must give the defaults of its `geom_*()` function ourselves if (requireNamespace("ggridges", quietly = TRUE)) { geom_density_ridges_pattern <- make_geom_pattern(ggridges::GeomDensityRidges, stat = ggridges::StatDensityRidges, position = ggridges::position_points_sina()) ggplot(iris, aes(Sepal.Length, Species, pattern = Species)) + geom_density_ridges_pattern(pattern_spacing = 0.03) }
make_GeomPattern() makes a pattern geom from a geom:
it draws the grob of geom and fills each of its areas with a pattern,
has the pattern aesthetics as well as those of geom,
and draws the key glyph of geom filled with the key's pattern.
The grob it draws is named after the pattern geom (e.g. "geom_smooth_pattern" for GeomSmoothPattern).
Use ggplot2::make_constructor() to make its geom_*_pattern() function,
make_geom_pattern() to make a geom_*_pattern() function from a geom_*() function,
or with_pattern() to make a pattern layer from a layer.
make_GeomPattern( geom, name = paste0(class(geom)[1L], "Pattern"), area_by = NULL )make_GeomPattern( geom, name = paste0(class(geom)[1L], "Pattern"), area_by = NULL )
geom |
A ggplot2::Geom object e.g. |
name |
The class name of the pattern geom. |
area_by |
How the areas of the grob the geom draws are matched to the rows of the data frame
its
By default what we know the draw method of Filling areas other than those of a |
A geom doesn't know the default stat and position of its geom_*() function
so pass them to ggplot2::make_constructor() if they aren't "identity"
e.g. stat = ggridges::StatDensityRidges, position = ggridges::position_points_sina()
for ggridges::geom_density_ridges()
(otherwise the layer may fail with an error about missing aesthetics the stat would have computed).
Nor does it know any other defaults its geom_*() function passes to its draw method
e.g. ggplot2::geom_smooth() passes se = TRUE (to draw its confidence band).
with_pattern() and make_geom_pattern() given the geom_*() function keep all of them.
The pattern geom stores a copy of geom as it is when make_GeomPattern() is called.
So if you call it at the top level of a package's code (which is run when the package is installed)
with a geom from another package the pattern geom won't pick up later updates of that geom
until your package is reinstalled:
call it in your package's .onLoad() instead or write the pattern geom's draw methods yourself
with with_pattern_aes() (see vignette("developing-pattern-geoms", package = "ggpattern")).
A ggplot2::Geom object.
A geom that is already a pattern geom (its default_aes has all the pattern aesthetics)
is returned as it is (or as a subclass of it called name if that is given)
and it is an error to set its area_by.
make_geom_pattern() to make a geom_*_pattern() function from a geom_*() function or a geom.
with_pattern() to make a pattern layer from a layer.
library("ggplot2") if (requireNamespace("ggridges", quietly = TRUE)) { GeomDensityRidgesPattern <- make_GeomPattern(ggridges::GeomDensityRidges) geom_density_ridges_pattern <- make_constructor(GeomDensityRidgesPattern, stat = ggridges::StatDensityRidges, position = ggridges::position_points_sina()) ggplot(iris, aes(Sepal.Length, Species, pattern = Species)) + geom_density_ridges_pattern(pattern_spacing = 0.03) }library("ggplot2") if (requireNamespace("ggridges", quietly = TRUE)) { GeomDensityRidgesPattern <- make_GeomPattern(ggridges::GeomDensityRidges) geom_density_ridges_pattern <- make_constructor(GeomDensityRidgesPattern, stat = ggridges::StatDensityRidges, position = ggridges::position_points_sina()) ggplot(iris, aes(Sepal.Length, Species, pattern = Species)) + geom_density_ridges_pattern(pattern_spacing = 0.03) }
Like {ggplot2}'s own scales our scale_pattern_*_discrete() and
scale_pattern_*_continuous() scales (e.g. the default scales used when a pattern aesthetic
is mapped without adding a scale)
look up their palette in the palette.<aesthetic>.<type> theme element
(e.g. palette.pattern_type.discrete or palette.pattern_angle.continuous)
when it isn't given by the scale's arguments.
A scale's palette is the first of:
Its palette argument.
Its choices or range argument (or other arguments like solid that set a palette).
The palette.<aesthetic>.discrete or palette.<aesthetic>.continuous theme element.
The scale's default palette (some scales such as scale_pattern_type_discrete() have none
and throw an error when the scale is used without one).
A theme palette element (like a scale's palette argument) must be one of:
A palette function e.g. scales::pal_rescale(c(0, 45)) for a continuous scale
or function(n) c(0, 45, 90)[seq_len(n)] for a discrete scale.
For pattern_colour, pattern_fill, and pattern_fill2:
a character vector of colours or the name of a palette (see scales::as_discrete_pal()
and scales::as_continuous_pal()).
For the discrete palettes of aesthetics that can take character values
(pattern, pattern_type, pattern_subtype, pattern_linetype, pattern_shape, pattern_filename, pattern_filter, pattern_gravity, pattern_orientation, pattern_grid, and pattern_units):
a character vector of values (used in order, see scales::pal_manual()).
Other vectors of values (e.g. numbers such as pch shapes for pattern_shape)
aren't converted into palettes ({ggplot2}'s own palette.shape.discrete has the same limitation):
wrap them in scales::pal_manual() for a discrete palette
(e.g. theme(palette.pattern_shape.discrete = scales::pal_manual(c(1, 2, 3))))
or use the scale's choices or range argument instead.
pattern_colour, pattern_fill, and pattern_fill2 have their own theme elements
(e.g. palette.pattern_fill.discrete) and don't use palette.colour.* or palette.fill.*
so that mapping fill and pattern_fill to the same variable doesn't draw
patterns the same colour as their background.
Their theme elements use the British spelling: palette.pattern_colour.* (not palette.pattern_color.*).
These theme elements only affect scales and hence mapped aesthetics. An unmapped pattern aesthetic still uses the pattern's own default.
if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_type = level, pattern_angle = outcome), pattern = "polygon_tiling", fill = "white", colour = "black" ) + theme_bw(18) + theme( palette.pattern_type.discrete = c("hexagonal", "rhombille", "pythagorean"), palette.pattern_angle.continuous = scales::pal_rescale(c(0, 45)) ) plot(gg) }if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_type = level, pattern_angle = outcome), pattern = "polygon_tiling", fill = "white", colour = "black" ) + theme_bw(18) + theme( palette.pattern_type.discrete = c("hexagonal", "rhombille", "pythagorean"), palette.pattern_angle.continuous = scales::pal_rescale(c(0, 45)) ) plot(gg) }
Scales for continuous pattern aesthetics
scale_pattern_angle_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_angle_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_density_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_density_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_spacing_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_spacing_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_xoffset_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_xoffset_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_yoffset_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_yoffset_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_aspect_ratio_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_aspect_ratio_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_key_scale_factor_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_key_scale_factor_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_scale_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_scale_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_phase_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_phase_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_frequency_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_frequency_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_res_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_res_discrete(..., range = NULL, palette = NULL, guide = "legend") scale_pattern_rot_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_rot_discrete(..., range = NULL, palette = NULL, guide = "legend")scale_pattern_angle_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_angle_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_density_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_density_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_spacing_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_spacing_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_xoffset_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_xoffset_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_yoffset_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_yoffset_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_aspect_ratio_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_aspect_ratio_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_key_scale_factor_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_key_scale_factor_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_scale_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_scale_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_phase_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_phase_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_frequency_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_frequency_discrete( ..., range = NULL, palette = NULL, guide = "legend" ) scale_pattern_res_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_res_discrete(..., range = NULL, palette = NULL, guide = "legend") scale_pattern_rot_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_rot_discrete(..., range = NULL, palette = NULL, guide = "legend")
name, breaks, labels, limits, trans, guide, ..., transform
|
See
|
range |
A numeric vector of length 2 of the minimum and maximum output values.
If |
palette |
A palette function e.g. |
A ggplot2::Scale object.
If neither the palette nor range argument nor the palette.<aesthetic>.<type>
theme element is set these scales use the following range:
pattern_angle: range = c(0, 90)
pattern_density: range = c(0, 0.5)
pattern_spacing: range = c(0.01, 0.1)
pattern_xoffset: range = c(0.01, 0.1)
pattern_yoffset: range = c(0.01, 0.1)
pattern_aspect_ratio: range = c(0.5, 2)
pattern_key_scale_factor: range = c(0.5, 2)
pattern_scale: range = c(0.5, 2)
pattern_phase: none (range, palette, or a theme palette must be set)
pattern_frequency: none (range, palette, or a theme palette must be set)
pattern_res: none (range, palette, or a theme palette must be set)
pattern_rot: range = c(0, 360)
if (require('ggplot2')) { # 'stripe' pattern example df <- data.frame(level = c('a', 'b', 'c', 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level, pattern_density = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_density_continuous(range = c(0.1, 0.6)) + labs( title = 'ggpattern::geom_col_pattern()', subtitle = 'pattern = \'stripe\'' ) plot(gg) }if (require('ggplot2')) { # 'stripe' pattern example df <- data.frame(level = c('a', 'b', 'c', 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level, pattern_density = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_density_continuous(range = c(0.1, 0.6)) + labs( title = 'ggpattern::geom_col_pattern()', subtitle = 'pattern = \'stripe\'' ) plot(gg) }
Scales for discrete pattern aesthetics
scale_pattern_type_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_type_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_subtype_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_subtype_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_filename_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_filename_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_filter_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_filter_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_gravity_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_gravity_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_orientation_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_orientation_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_grid_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_grid_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_units_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_units_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", na.value = "none", palette = NULL ) scale_pattern_discrete( ..., choices = NULL, palette = NULL, guide = "legend", na.value = "none" )scale_pattern_type_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_type_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_subtype_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_subtype_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_filename_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_filename_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_filter_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_filter_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_gravity_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_gravity_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_orientation_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_orientation_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_grid_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_grid_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_units_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_units_discrete( ..., choices = NULL, palette = NULL, guide = "legend" ) scale_pattern_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, choices = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", na.value = "none", palette = NULL ) scale_pattern_discrete( ..., choices = NULL, palette = NULL, guide = "legend", na.value = "none" )
name, breaks, labels, limits, trans, guide, ..., transform, na.value
|
See
|
choices |
vector of values to choose from.
If |
palette |
A palette function, or for a discrete scale a character vector of values
(used in order, see |
A ggplot2::Scale object.
If neither the palette nor choices argument nor the palette.<aesthetic>.<type>
theme element is set these scales use the following choices:
pattern: choices = c('stripe', 'crosshatch', 'circle')
pattern_type: none (choices, palette, or a theme palette must be set)
pattern_subtype: none (choices, palette, or a theme palette must be set)
pattern_filename: none (choices, palette, or a theme palette must be set)
pattern_filter: choices = c('lanczos', 'box', 'spline', 'cubic')
pattern_gravity: choices = c('center', 'north', 'south', 'east', 'west', 'northeast', 'northwest', 'southeast', 'southwest')
pattern_orientation: choices = c('horizontal', 'vertical', 'radial')
pattern_grid: choices = c('square', 'hex')
pattern_units: choices = c('snpc', 'cm', 'inches')
if (require('ggplot2')) { gg <- ggplot(mtcars) + geom_density_pattern( aes( x = mpg, pattern_fill = as.factor(cyl), pattern_type = as.factor(cyl) ), pattern = 'polygon_tiling', pattern_key_scale_factor = 1.2 ) + scale_pattern_type_discrete(choices = gridpattern::names_polygon_tiling) + theme_bw(18) + theme(legend.key.size = unit(2, 'cm')) + labs( title = 'ggpattern::geom_density_pattern()', subtitle = 'pattern = \'polygon_tiling\'' ) plot(gg) }if (require('ggplot2')) { gg <- ggplot(mtcars) + geom_density_pattern( aes( x = mpg, pattern_fill = as.factor(cyl), pattern_type = as.factor(cyl) ), pattern = 'polygon_tiling', pattern_key_scale_factor = 1.2 ) + scale_pattern_type_discrete(choices = gridpattern::names_polygon_tiling) + theme_bw(18) + theme(legend.key.size = unit(2, 'cm')) + labs( title = 'ggpattern::geom_density_pattern()', subtitle = 'pattern = \'polygon_tiling\'' ) plot(gg) }
See ggplot2::scale_alpha() for details.
scale_pattern_alpha_continuous(..., range = NULL, palette = NULL) scale_pattern_alpha(..., range = NULL, palette = NULL) scale_pattern_alpha_discrete(...) scale_pattern_alpha_ordinal(..., range = NULL, palette = NULL)scale_pattern_alpha_continuous(..., range = NULL, palette = NULL) scale_pattern_alpha(..., range = NULL, palette = NULL) scale_pattern_alpha_discrete(...) scale_pattern_alpha_ordinal(..., range = NULL, palette = NULL)
... |
Other arguments passed on to |
range |
Output range of alpha values. Must lie between 0 and 1.
If |
palette |
A palette function e.g. |
A ggplot2::Scale object.
if (require("ggplot2")) { # 'stripe' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level, pattern_alpha = outcome), pattern_density = 0.6, pattern_linewidth = 1.5, pattern = 'stripe', fill = 'white', colour = 'black', linewidth = 1.5 ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_alpha() + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'stripe'" ) plot(gg) }if (require("ggplot2")) { # 'stripe' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level, pattern_alpha = outcome), pattern_density = 0.6, pattern_linewidth = 1.5, pattern = 'stripe', fill = 'white', colour = 'black', linewidth = 1.5 ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_alpha() + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'stripe'" ) plot(gg) }
The brewer scales provides sequential, diverging and qualitative
colour schemes from ColorBrewer. These are particularly well suited to
display discrete values on a map. See https://colorbrewer2.org for
more information.
scale_pattern_colour_brewer( ..., type = "seq", palette = 1, direction = 1, aesthetics = "pattern_colour" ) scale_pattern_fill_brewer( ..., type = "seq", palette = 1, direction = 1, aesthetics = "pattern_fill" ) scale_pattern_fill2_brewer( ..., type = "seq", palette = 1, direction = 1, aesthetics = "pattern_fill2" ) scale_pattern_colour_distiller( ..., type = "seq", palette = 1, direction = -1, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour" ) scale_pattern_fill_distiller( ..., type = "seq", palette = 1, direction = -1, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill" ) scale_pattern_fill2_distiller( ..., type = "seq", palette = 1, direction = -1, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2" )scale_pattern_colour_brewer( ..., type = "seq", palette = 1, direction = 1, aesthetics = "pattern_colour" ) scale_pattern_fill_brewer( ..., type = "seq", palette = 1, direction = 1, aesthetics = "pattern_fill" ) scale_pattern_fill2_brewer( ..., type = "seq", palette = 1, direction = 1, aesthetics = "pattern_fill2" ) scale_pattern_colour_distiller( ..., type = "seq", palette = 1, direction = -1, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour" ) scale_pattern_fill_distiller( ..., type = "seq", palette = 1, direction = -1, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill" ) scale_pattern_fill2_distiller( ..., type = "seq", palette = 1, direction = -1, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2" )
... |
Other arguments passed on to |
palette |
If a string, will use that named palette. If a number, will index into
the list of palettes of appropriate |
direction, type, aesthetics, values, space, na.value, guide
|
See |
The brewer scales were carefully designed and tested on discrete data.
They were not designed to be extended to continuous data, but results often
look good. Your mileage may vary.
A ggplot2::Scale object.
The following palettes are available for use with these scales:
BrBG, PiYG, PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, Spectral
Accent, Dark2, Paired, Pastel1, Pastel2, Set1, Set2, Set3
Blues, BuGn, BuPu, GnBu, Greens, Greys, Oranges, OrRd, PuBu, PuBuGn, PuRd, Purples, RdPu, Reds, YlGn, YlGnBu, YlOrBr, YlOrRd
Modify the palette through the palette arguement.
The distiller scales extend brewer to continuous scales by smoothly
interpolating 7 colours from any palette to a continuous scale. The fermenter
scales provide binned versions of the brewer scales.
if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) # discrete 'brewer' palette gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_brewer() plot(gg) # continuous 'distiller' palette gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_distiller() plot(gg) }if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) # discrete 'brewer' palette gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_brewer() plot(gg) # continuous 'distiller' palette gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_distiller() plot(gg) }
These are the default scales for the pattern_colour, pattern_fill, and pattern_fill2 aesthetics.
See ggplot2::scale_colour_continuous() and ggplot2::scale_colour_discrete() for more information.
scale_pattern_colour_continuous( ..., palette = NULL, aesthetics = "pattern_colour", guide = guide_colourbar(available_aes = standardise_aes_names(aesthetics)), na.value = "grey50", type = getOption("ggplot2.continuous.colour") ) scale_pattern_fill_continuous( ..., palette = NULL, aesthetics = "pattern_fill", guide = guide_colourbar(available_aes = standardise_aes_names(aesthetics)), na.value = "grey50", type = getOption("ggplot2.continuous.fill") ) scale_pattern_fill2_continuous( ..., palette = NULL, aesthetics = "pattern_fill2", guide = guide_colourbar(available_aes = standardise_aes_names(aesthetics)), na.value = "grey50", type = getOption("ggplot2.continuous.fill") ) scale_pattern_colour_discrete( ..., palette = NULL, aesthetics = "pattern_colour", na.value = "grey50" ) scale_pattern_fill_discrete( ..., palette = NULL, aesthetics = "pattern_fill", na.value = "grey50" ) scale_pattern_fill2_discrete( ..., palette = NULL, aesthetics = "pattern_fill2", na.value = "grey50" )scale_pattern_colour_continuous( ..., palette = NULL, aesthetics = "pattern_colour", guide = guide_colourbar(available_aes = standardise_aes_names(aesthetics)), na.value = "grey50", type = getOption("ggplot2.continuous.colour") ) scale_pattern_fill_continuous( ..., palette = NULL, aesthetics = "pattern_fill", guide = guide_colourbar(available_aes = standardise_aes_names(aesthetics)), na.value = "grey50", type = getOption("ggplot2.continuous.fill") ) scale_pattern_fill2_continuous( ..., palette = NULL, aesthetics = "pattern_fill2", guide = guide_colourbar(available_aes = standardise_aes_names(aesthetics)), na.value = "grey50", type = getOption("ggplot2.continuous.fill") ) scale_pattern_colour_discrete( ..., palette = NULL, aesthetics = "pattern_colour", na.value = "grey50" ) scale_pattern_fill_discrete( ..., palette = NULL, aesthetics = "pattern_fill", na.value = "grey50" ) scale_pattern_fill2_discrete( ..., palette = NULL, aesthetics = "pattern_fill2", na.value = "grey50" )
... |
Additional parameters passed on to the scale |
palette |
A palette function (or something that |
aesthetics |
The names of the aesthetics that this scale works with. |
guide |
A function used to create a guide or its name. |
na.value |
Colour to use for missing values. |
type |
One of "gradient" or "viridis" indicating the
colour scale to use.
If |
The palette is the first of the palette argument,
the scale type (or arguments of scale_pattern_colour_gradient() or scale_pattern_colour_hue()),
the palette.<aesthetic>.<type> theme element (e.g. palette.pattern_fill.discrete, see pattern_palettes),
and the default palette (scales::pal_seq_gradient() from "#132B43" to "#56B1F7" for continuous scales
and scales::pal_hue() for discrete scales).
These scales don't use the palette.colour.<type> or palette.fill.<type> theme elements.
A ggplot2::Scale object.
if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_continuous() plot(gg) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_discrete(palette = scales::pal_brewer(palette = "Set1")) plot(gg) }if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_continuous() plot(gg) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_discrete(palette = scales::pal_brewer(palette = "Set1")) plot(gg) }
See ggplot2::scale_colour_gradient() for more information
scale_pattern_colour_gradient( ..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour" ) scale_pattern_fill_gradient( ..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill" ) scale_pattern_fill2_gradient( ..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2" ) scale_pattern_colour_gradient2( ..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour" ) scale_pattern_fill_gradient2( ..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill" ) scale_pattern_fill2_gradient2( ..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2" ) scale_pattern_colour_gradientn( ..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour", colors ) scale_pattern_fill_gradientn( ..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill", colors ) scale_pattern_fill2_gradientn( ..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2", colors )scale_pattern_colour_gradient( ..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour" ) scale_pattern_fill_gradient( ..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill" ) scale_pattern_fill2_gradient( ..., low = "#132B43", high = "#56B1F7", space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2" ) scale_pattern_colour_gradient2( ..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour" ) scale_pattern_fill_gradient2( ..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill" ) scale_pattern_fill2_gradient2( ..., low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2" ) scale_pattern_colour_gradientn( ..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour", colors ) scale_pattern_fill_gradientn( ..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill", colors ) scale_pattern_fill2_gradientn( ..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2", colors )
low, high
|
Colours for low and high ends of the gradient. |
space, ..., na.value, aesthetics
|
See |
guide |
Type of legend. Use |
mid |
colour for mid point |
midpoint |
The midpoint (in data value) of the diverging scale. Defaults to 0. |
colours, colors
|
Vector of colours to use for n-colour gradient. |
values |
if colours should not be evenly positioned along the gradient
this vector gives the position (between 0 and 1) for each colour in the
|
scale_*_gradient creates a two colour gradient (low-high),
scale_*_gradient2 creates a diverging colour gradient (low-mid-high),
scale_*_gradientn creates a n-colour gradient.
A ggplot2::Scale object.
if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_gradient() plot(gg) }if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_gradient() plot(gg) }
Based on gray.colors(). This is black and white equivalent
of scale_pattern_colour_gradient().
scale_pattern_colour_grey( ..., start = 0.2, end = 0.8, na.value = "red", aesthetics = "pattern_colour" ) scale_pattern_fill_grey( ..., start = 0.2, end = 0.8, na.value = "red", aesthetics = "pattern_fill" ) scale_pattern_fill2_grey( ..., start = 0.2, end = 0.8, na.value = "red", aesthetics = "pattern_fill2" )scale_pattern_colour_grey( ..., start = 0.2, end = 0.8, na.value = "red", aesthetics = "pattern_colour" ) scale_pattern_fill_grey( ..., start = 0.2, end = 0.8, na.value = "red", aesthetics = "pattern_fill" ) scale_pattern_fill2_grey( ..., start = 0.2, end = 0.8, na.value = "red", aesthetics = "pattern_fill2" )
..., start, end, na.value, aesthetics
|
See
|
A ggplot2::Scale object.
if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_grey() plot(gg) }if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_grey() plot(gg) }
This is the default colour scale for categorical variables. It maps each level to an evenly spaced hue on the colour wheel. It does not generate colour-blind safe palettes.
scale_pattern_colour_hue( ..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "pattern_colour" ) scale_pattern_fill_hue( ..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "pattern_fill" ) scale_pattern_fill2_hue( ..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "pattern_fill2" )scale_pattern_colour_hue( ..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "pattern_colour" ) scale_pattern_fill_hue( ..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "pattern_fill" ) scale_pattern_fill2_hue( ..., h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1, na.value = "grey50", aesthetics = "pattern_fill2" )
h, c, l, h.start, direction, ...
|
See |
na.value |
Colour to use for missing values |
aesthetics |
Character string or vector of character strings listing the
name(s) of the aesthetic(s) that this scale works with. This can be useful, for
example, to apply colour settings to the |
A ggplot2::Scale object.
if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_hue() plot(gg) }if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_hue() plot(gg) }
The viridis scales provide colour maps that are perceptually uniform in both
colour and black-and-white. They are also designed to be perceived by viewers
with common forms of colour blindness. See also
https://bids.github.io/colormap/.
scale_pattern_colour_viridis_d( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "pattern_colour" ) scale_pattern_fill_viridis_d( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "pattern_fill" ) scale_pattern_fill2_viridis_d( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "pattern_fill2" ) scale_pattern_colour_viridis_c( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour" ) scale_pattern_fill_viridis_c( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill" ) scale_pattern_fill2_viridis_c( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2" )scale_pattern_colour_viridis_d( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "pattern_colour" ) scale_pattern_fill_viridis_d( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "pattern_fill" ) scale_pattern_fill2_viridis_d( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "pattern_fill2" ) scale_pattern_colour_viridis_c( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_colour"), aesthetics = "pattern_colour" ) scale_pattern_fill_viridis_c( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill"), aesthetics = "pattern_fill" ) scale_pattern_fill2_viridis_c( ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = guide_colourbar(available_aes = "pattern_fill2"), aesthetics = "pattern_fill2" )
... |
Other arguments passed on to |
begin, end, alpha, direction, option, values, space, na.value, guide
|
See |
aesthetics |
Character string or vector of character strings listing the
name(s) of the aesthetic(s) that this scale works with. This can be useful, for
example, to apply colour settings to the |
A ggplot2::Scale object.
if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) # discrete 'viridis' palette gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_viridis_d() plot(gg) # continuous 'viridis' palette gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_viridis_c() plot(gg) }if (require("ggplot2")) { df <- data.frame(level = c("a", "b", "c", "d"), outcome = c(2.3, 1.9, 3.2, 1)) # discrete 'viridis' palette gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_viridis_d() plot(gg) # continuous 'viridis' palette gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = outcome), pattern = 'stripe', fill = 'white', colour = 'black' ) + theme_bw(18) + scale_pattern_fill_viridis_c() plot(gg) }
Use values without scaling
scale_pattern_type_identity(..., guide = "none") scale_pattern_subtype_identity(..., guide = "none") scale_pattern_angle_identity(..., guide = "none") scale_pattern_density_identity(..., guide = "none") scale_pattern_spacing_identity(..., guide = "none") scale_pattern_xoffset_identity(..., guide = "none") scale_pattern_yoffset_identity(..., guide = "none") scale_pattern_alpha_identity(..., guide = "none") scale_pattern_linetype_identity(..., guide = "none") scale_pattern_linewidth_identity(..., guide = "none") scale_pattern_size_identity(..., guide = "none") scale_pattern_shape_identity(..., guide = "none") scale_pattern_colour_identity(..., guide = "none") scale_pattern_fill_identity(..., guide = "none") scale_pattern_fill2_identity(..., guide = "none") scale_pattern_aspect_ratio_identity(..., guide = "none") scale_pattern_key_scale_factor_identity(..., guide = "none") scale_pattern_filename_identity(..., guide = "none") scale_pattern_filter_identity(..., guide = "none") scale_pattern_gravity_identity(..., guide = "none") scale_pattern_scale_identity(..., guide = "none") scale_pattern_orientation_identity(..., guide = "none") scale_pattern_phase_identity(..., guide = "none") scale_pattern_frequency_identity(..., guide = "none") scale_pattern_grid_identity(..., guide = "none") scale_pattern_res_identity(..., guide = "none") scale_pattern_rot_identity(..., guide = "none") scale_pattern_units_identity(..., guide = "none") scale_pattern_identity(..., guide = "none")scale_pattern_type_identity(..., guide = "none") scale_pattern_subtype_identity(..., guide = "none") scale_pattern_angle_identity(..., guide = "none") scale_pattern_density_identity(..., guide = "none") scale_pattern_spacing_identity(..., guide = "none") scale_pattern_xoffset_identity(..., guide = "none") scale_pattern_yoffset_identity(..., guide = "none") scale_pattern_alpha_identity(..., guide = "none") scale_pattern_linetype_identity(..., guide = "none") scale_pattern_linewidth_identity(..., guide = "none") scale_pattern_size_identity(..., guide = "none") scale_pattern_shape_identity(..., guide = "none") scale_pattern_colour_identity(..., guide = "none") scale_pattern_fill_identity(..., guide = "none") scale_pattern_fill2_identity(..., guide = "none") scale_pattern_aspect_ratio_identity(..., guide = "none") scale_pattern_key_scale_factor_identity(..., guide = "none") scale_pattern_filename_identity(..., guide = "none") scale_pattern_filter_identity(..., guide = "none") scale_pattern_gravity_identity(..., guide = "none") scale_pattern_scale_identity(..., guide = "none") scale_pattern_orientation_identity(..., guide = "none") scale_pattern_phase_identity(..., guide = "none") scale_pattern_frequency_identity(..., guide = "none") scale_pattern_grid_identity(..., guide = "none") scale_pattern_res_identity(..., guide = "none") scale_pattern_rot_identity(..., guide = "none") scale_pattern_units_identity(..., guide = "none") scale_pattern_identity(..., guide = "none")
..., guide
|
See |
A ggplot2::Scale object.
if (require('ggplot2')) { df <- data.frame(outcome = c(2.3, 1.9, 3.2, 1), pattern_type = sample(gridpattern::names_polygon_tiling, 4)) gg <- ggplot(df) + geom_col_pattern( aes(pattern_type, outcome, pattern_fill = pattern_type, pattern_type = pattern_type), colour = 'black', pattern = 'polygon_tiling', pattern_key_scale_factor = 1.2 ) + scale_pattern_type_identity() + theme_bw(18) + theme(legend.position = 'none') + labs( x = 'level', title = 'ggpattern::geom_col_pattern()', subtitle = 'pattern = \'polygon_tiling\'' ) plot(gg) }if (require('ggplot2')) { df <- data.frame(outcome = c(2.3, 1.9, 3.2, 1), pattern_type = sample(gridpattern::names_polygon_tiling, 4)) gg <- ggplot(df) + geom_col_pattern( aes(pattern_type, outcome, pattern_fill = pattern_type, pattern_type = pattern_type), colour = 'black', pattern = 'polygon_tiling', pattern_key_scale_factor = 1.2 ) + scale_pattern_type_identity() + theme_bw(18) + theme(legend.position = 'none') + labs( x = 'level', title = 'ggpattern::geom_col_pattern()', subtitle = 'pattern = \'polygon_tiling\'' ) plot(gg) }
Default line types based on a set supplied by Richard Pearson, University of Manchester. Continuous values can not be mapped to line types.
scale_pattern_linetype(..., na.value = "blank", palette = NULL) scale_pattern_linetype_continuous(...) scale_pattern_linetype_discrete(..., na.value = "blank", palette = NULL)scale_pattern_linetype(..., na.value = "blank", palette = NULL) scale_pattern_linetype_continuous(...) scale_pattern_linetype_discrete(..., na.value = "blank", palette = NULL)
... |
see |
na.value |
The linetype to use for |
palette |
A palette function or a character vector of linetypes (see |
A ggplot2::Scale object.
if (require("ggplot2")) { # 'stripe' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level, pattern_linetype = level), pattern_density = 0.6, pattern_linewidth = 1.5, pattern = 'stripe', fill = 'white', colour = 'black', linewidth = 1.5 ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_linetype() + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'stripe'" ) plot(gg) }if (require("ggplot2")) { # 'stripe' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level, pattern_linetype = level), pattern_density = 0.6, pattern_linewidth = 1.5, pattern = 'stripe', fill = 'white', colour = 'black', linewidth = 1.5 ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_linetype() + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'stripe'" ) plot(gg) }
scale_pattern_linewidth() scales the width of lines (e.g. the stripes of the "stripe" pattern).
It is the pattern analogue of ggplot2::scale_linewidth().
The pattern_linewidth aesthetic supersedes using pattern_size for line widths
(if pattern_linewidth is unset it falls back to pattern_size).
Use scale_pattern_size() for the fontsize of the "text" pattern.
scale_pattern_linewidth_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_linewidth( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, guide = "legend", ..., transform = "identity", palette = NULL )scale_pattern_linewidth_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_linewidth( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, guide = "legend", ..., transform = "identity", palette = NULL )
name, breaks, labels, limits, guide, ..., transform
|
See |
range |
a numeric vector of length 2 that specifies the minimum and
maximum line width after transformation.
If |
palette |
A palette function e.g. |
A ggplot2::Scale object.
if (require("ggplot2")) { # 'circle' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level, linewidth = outcome, pattern_linewidth = outcome), pattern_density = 0.4, pattern_spacing = 0.3, pattern = 'circle', fill = 'white', colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_linewidth() + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'circle'" ) plot(gg) }if (require("ggplot2")) { # 'circle' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_fill = level, linewidth = outcome, pattern_linewidth = outcome), pattern_density = 0.4, pattern_spacing = 0.3, pattern = 'circle', fill = 'white', colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_linewidth() + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'circle'" ) plot(gg) }
Create your own discrete scale
scale_pattern_type_manual(..., values, breaks = waiver()) scale_pattern_subtype_manual(..., values, breaks = waiver()) scale_pattern_angle_manual(..., values, breaks = waiver()) scale_pattern_density_manual(..., values, breaks = waiver()) scale_pattern_spacing_manual(..., values, breaks = waiver()) scale_pattern_xoffset_manual(..., values, breaks = waiver()) scale_pattern_yoffset_manual(..., values, breaks = waiver()) scale_pattern_alpha_manual(..., values, breaks = waiver()) scale_pattern_linetype_manual(..., values, breaks = waiver()) scale_pattern_linewidth_manual(..., values, breaks = waiver()) scale_pattern_size_manual(..., values, breaks = waiver()) scale_pattern_shape_manual(..., values, breaks = waiver()) scale_pattern_colour_manual(..., values, breaks = waiver()) scale_pattern_fill_manual(..., values, breaks = waiver()) scale_pattern_fill2_manual(..., values, breaks = waiver()) scale_pattern_aspect_ratio_manual(..., values, breaks = waiver()) scale_pattern_key_scale_factor_manual(..., values, breaks = waiver()) scale_pattern_filename_manual(..., values, breaks = waiver()) scale_pattern_filter_manual(..., values, breaks = waiver()) scale_pattern_gravity_manual(..., values, breaks = waiver()) scale_pattern_scale_manual(..., values, breaks = waiver()) scale_pattern_orientation_manual(..., values, breaks = waiver()) scale_pattern_phase_manual(..., values, breaks = waiver()) scale_pattern_frequency_manual(..., values, breaks = waiver()) scale_pattern_grid_manual(..., values, breaks = waiver()) scale_pattern_res_manual(..., values, breaks = waiver()) scale_pattern_rot_manual(..., values, breaks = waiver()) scale_pattern_units_manual(..., values, breaks = waiver()) scale_pattern_manual(..., values, breaks = waiver(), na.value = "none")scale_pattern_type_manual(..., values, breaks = waiver()) scale_pattern_subtype_manual(..., values, breaks = waiver()) scale_pattern_angle_manual(..., values, breaks = waiver()) scale_pattern_density_manual(..., values, breaks = waiver()) scale_pattern_spacing_manual(..., values, breaks = waiver()) scale_pattern_xoffset_manual(..., values, breaks = waiver()) scale_pattern_yoffset_manual(..., values, breaks = waiver()) scale_pattern_alpha_manual(..., values, breaks = waiver()) scale_pattern_linetype_manual(..., values, breaks = waiver()) scale_pattern_linewidth_manual(..., values, breaks = waiver()) scale_pattern_size_manual(..., values, breaks = waiver()) scale_pattern_shape_manual(..., values, breaks = waiver()) scale_pattern_colour_manual(..., values, breaks = waiver()) scale_pattern_fill_manual(..., values, breaks = waiver()) scale_pattern_fill2_manual(..., values, breaks = waiver()) scale_pattern_aspect_ratio_manual(..., values, breaks = waiver()) scale_pattern_key_scale_factor_manual(..., values, breaks = waiver()) scale_pattern_filename_manual(..., values, breaks = waiver()) scale_pattern_filter_manual(..., values, breaks = waiver()) scale_pattern_gravity_manual(..., values, breaks = waiver()) scale_pattern_scale_manual(..., values, breaks = waiver()) scale_pattern_orientation_manual(..., values, breaks = waiver()) scale_pattern_phase_manual(..., values, breaks = waiver()) scale_pattern_frequency_manual(..., values, breaks = waiver()) scale_pattern_grid_manual(..., values, breaks = waiver()) scale_pattern_res_manual(..., values, breaks = waiver()) scale_pattern_rot_manual(..., values, breaks = waiver()) scale_pattern_units_manual(..., values, breaks = waiver()) scale_pattern_manual(..., values, breaks = waiver(), na.value = "none")
..., values, breaks, na.value
|
See |
A ggplot2::Scale object.
if (require('ggplot2')) { gg <- ggplot(mtcars) + geom_density_pattern( aes( x = mpg, pattern_fill = as.factor(cyl), pattern_type = as.factor(cyl) ), pattern = 'polygon_tiling', pattern_key_scale_factor = 1.2 ) + scale_pattern_type_manual(values = c('hexagonal', 'rhombille', 'pythagorean')) + theme_bw(18) + theme(legend.key.size = unit(2, 'cm')) + labs( title = 'ggpattern::geom_density_pattern()', subtitle = 'pattern = \'polygon_tiling\'' ) plot(gg) }if (require('ggplot2')) { gg <- ggplot(mtcars) + geom_density_pattern( aes( x = mpg, pattern_fill = as.factor(cyl), pattern_type = as.factor(cyl) ), pattern = 'polygon_tiling', pattern_key_scale_factor = 1.2 ) + scale_pattern_type_manual(values = c('hexagonal', 'rhombille', 'pythagorean')) + theme_bw(18) + theme(legend.key.size = unit(2, 'cm')) + labs( title = 'ggpattern::geom_density_pattern()', subtitle = 'pattern = \'polygon_tiling\'' ) plot(gg) }
scale_pattern_shape maps discrete variables to six easily discernible shapes.
If you have more than six levels, you will get a warning message, and the
seventh and subsequence levels will not appear on the plot. Use
scale_pattern_shape_manual() to supply your own values. You can not map
a continuous variable to shape unless scale_pattern_shape_binned() is used. Still,
as shape has no inherent order, this use is not advised..
scale_pattern_shape(..., solid = NULL, palette = NULL) scale_pattern_shape_discrete(..., solid = NULL, palette = NULL) scale_pattern_shape_ordinal(...) scale_pattern_shape_continuous(...)scale_pattern_shape(..., solid = NULL, palette = NULL) scale_pattern_shape_discrete(..., solid = NULL, palette = NULL) scale_pattern_shape_ordinal(...) scale_pattern_shape_continuous(...)
... |
other arguments passed to discrete_scale() |
solid |
Should the shapes be solid, |
palette |
A palette function or a character vector of shapes (see |
Scales for area or radius
A ggplot2::Scale object.
if (require("ggplot2")) { # 'pch' pattern example gg <- ggplot(mtcars, aes(as.factor(cyl), mpg)) + geom_violin_pattern(aes(fill = as.factor(cyl), pattern_shape = as.factor(cyl)), pattern = 'pch', pattern_density = 0.3, pattern_angle = 0, colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_shape() + labs( title = "ggpattern::geom_violin_pattern()", subtitle = "pattern = 'pch'" ) plot(gg) }if (require("ggplot2")) { # 'pch' pattern example gg <- ggplot(mtcars, aes(as.factor(cyl), mpg)) + geom_violin_pattern(aes(fill = as.factor(cyl), pattern_shape = as.factor(cyl)), pattern = 'pch', pattern_density = 0.3, pattern_angle = 0, colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_shape() + labs( title = "ggpattern::geom_violin_pattern()", subtitle = "pattern = 'pch'" ) plot(gg) }
scale_pattern_size() scales the fontsize of the "text" pattern.
Using pattern_size for the line widths of other patterns is superseded by
the pattern_linewidth aesthetic and scale_pattern_linewidth()
(an unset pattern_linewidth still falls back to pattern_size for backwards compatibility).
scale_pattern_size_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_size( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL )scale_pattern_size_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL ) scale_pattern_size( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = NULL, trans = deprecated(), guide = "legend", ..., transform = "identity", palette = NULL )
name, breaks, labels, limits, trans, guide, ..., transform
|
See |
range |
a numeric vector of length 2 that specifies the minimum and
maximum size after transformation.
If |
palette |
A palette function e.g. |
A ggplot2::Scale object.
if (require("ggplot2")) { # 'text' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_colour = level, pattern_size = outcome), pattern_spacing = 0.08, pattern_angle = 0, pattern = 'text', fill = 'white', colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_size(range = c(6, 18)) + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'text'" ) plot(gg) }if (require("ggplot2")) { # 'text' pattern example df <- data.frame(level = c("a", "b", "c", 'd'), outcome = c(2.3, 1.9, 3.2, 1)) gg <- ggplot(df) + geom_col_pattern( aes(level, outcome, pattern_colour = level, pattern_size = outcome), pattern_spacing = 0.08, pattern_angle = 0, pattern = 'text', fill = 'white', colour = 'black' ) + theme_bw(18) + theme(legend.position = 'none') + scale_pattern_size(range = c(6, 18)) + labs( title = "ggpattern::geom_col_pattern()", subtitle = "pattern = 'text'" ) plot(gg) }
with_pattern_aes() fills each area of a grob
(e.g. the grob drawn by a {ggplot2} geom's draw method)
with the pattern of its row of a layer's data
and with_pattern_key() fills each area of a legend key glyph with the key's pattern.
They are wrappers around gridpattern::with_pattern() for writing the
draw_panel() / draw_group() and draw_key() methods of a pattern geom
(see vignette("developing-pattern-geoms", package = "ggpattern")).
with_pattern_aes(grob, data, pool = FALSE, legend = FALSE, delay = FALSE) with_pattern_key(key, data, size, aspect_ratio = get_aspect_ratio())with_pattern_aes(grob, data, pool = FALSE, legend = FALSE, delay = FALSE) with_pattern_key(key, data, size, aspect_ratio = get_aspect_ratio())
grob |
A grid grob (usually the grob drawn by the parent |
data |
A data frame of aesthetics with either
one row per area of |
pool, legend
|
Passed to |
delay |
If |
key |
A grid grob: a |
size, aspect_ratio
|
As in |
The pattern aesthetics (e.g. pattern and pattern_fill) are the pattern parameters
and the other columns (e.g. fill and colour) are passed on as well
for the (custom) patterns that use them,
except the x and y positions, PANEL,
and the names of the arguments of gridpattern::with_pattern() and gridpattern::patternGrob()
(id, name, gp, vp, boundary, default.units, draw, pool, layers, delay,
leaves, legend, and prefix).
The pattern column is the pattern's name ("stripe" if there isn't one).
A grob.
make_GeomPattern() to make a pattern geom from a geom without writing its draw methods.
default_pattern_aes() for the default pattern aesthetics.
grob <- grid::rectGrob(x = c(0.25, 0.75), width = 0.4, height = 0.8, gp = grid::gpar(fill = c("grey80", "grey60"))) data <- data.frame(pattern = c("stripe", "circle"), pattern_fill = c("blue", "red")) grid::grid.newpage() grid::grid.draw(with_pattern_aes(grob, data)) # e.g. the `draw_key()` method of a pattern geom draw_key <- function(data, params, size) { with_pattern_key(ggplot2::draw_key_polygon(data, params, size), data, size) }grob <- grid::rectGrob(x = c(0.25, 0.75), width = 0.4, height = 0.8, gp = grid::gpar(fill = c("grey80", "grey60"))) data <- data.frame(pattern = c("stripe", "circle"), pattern_fill = c("blue", "red")) grid::grid.newpage() grid::grid.draw(with_pattern_aes(grob, data)) # e.g. the `draw_key()` method of a pattern geom draw_key <- function(data, params, size) { with_pattern_key(ggplot2::draw_key_polygon(data, params, size), data, size) }
The Layer method of with_pattern() makes a pattern layer from a {ggplot2} layer:
the layer's geom is replaced by our pattern geom for it if we have one
(e.g. GeomRectPattern for ggplot2::GeomRect)
or else by the pattern geom make_GeomPattern() makes from it.
## S3 method for class 'Layer' with_pattern(x, ..., mapping = NULL, area_by = NULL) ## S3 method for class 'gg' with_pattern(x, ...) ## S3 method for class 'Geom' with_pattern(x, ...) ## S3 method for class 'ggplot' with_pattern(x, ...)## S3 method for class 'Layer' with_pattern(x, ..., mapping = NULL, area_by = NULL) ## S3 method for class 'gg' with_pattern(x, ...) ## S3 method for class 'Geom' with_pattern(x, ...) ## S3 method for class 'ggplot' with_pattern(x, ...)
x |
A |
... |
Pattern aesthetics set to a constant e.g. |
mapping |
Pattern aesthetic mappings (created by |
area_by |
Passed to |
Some {ggplot2} functions return a list instead of a layer
e.g. ggplot2::geom_sf() returns a list of a layer and a ggplot2::coord_sf().
The list method of with_pattern() makes a pattern layer from each layer in such a list
and the gg method leaves any other {ggplot2} object (which has no areas to fill)
as it is (whatever the other arguments)
e.g. a coord, scale, facet, theme, ggplot2::labs(), or ggplot2::guides()
(a NULL in the list is left as it is too).
So e.g. with_pattern(geom_sf(), pattern = "circle") works too.
It is an error to give it a plot: give it the plot's layers instead
e.g. ggplot(df, aes(x, y)) + with_pattern(geom_col()).
It is also an error to give it a geom (e.g. ggplot2::GeomCol): use make_GeomPattern() instead.
To combine it with a {ggfx} filter make the pattern layer first
e.g. ggfx::with_blur(with_pattern(geom_col())):
the layer of with_pattern(ggfx::with_blur(geom_col())) is drawn without its patterns
(since {ggfx} draws the layer with the draw methods of the geom it was given).
A {ggplot2} layer (or the other {ggplot2} object).
make_GeomPattern() to make a pattern geom from a geom.
library("ggplot2") if (requireNamespace("magick", quietly = TRUE)) { magick::magick_set_seed(42) ggplot(mtcars, aes(mpg, wt)) + geom_point() + with_pattern(geom_smooth(method = "lm", formula = y ~ x), pattern = "plasma", pattern_alpha = 0.7) }library("ggplot2") if (requireNamespace("magick", quietly = TRUE)) { magick::magick_set_seed(42) ggplot(mtcars, aes(mpg, wt)) + geom_point() + with_pattern(geom_smooth(method = "lm", formula = y ~ x), pattern = "plasma", pattern_alpha = 0.7) }