| Title: | Extra Themes, Scales and Geoms for 'ggplot2' |
|---|---|
| Description: | Some extra themes, geoms, and scales for 'ggplot2'. Provides 'ggplot2' themes and scales that replicate the look of plots by Edward Tufte, Stephen Few, 'Fivethirtyeight', 'The Economist', 'Stata', 'Excel', and 'The Wall Street Journal', among others. Provides 'geoms' for Tufte's box plot and range frame. |
| Authors: | Jeffrey B. Arnold [aut, cre, cph]
|
| Maintainer: | Jeffrey B. Arnold <[email protected]> |
| License: | GPL-2 |
| Version: | 7.0.0.9000 |
| Built: | 2026-10-07 08:45:56 UTC |
| Source: | https://github.com/jrnold/ggthemes |
A convenience wrapper around bank_slopes() that extracts
x/y directly from an already-specified ggplot, so
you do not have to separately reconstruct the plotted vectors by hand.
It builds plot with ggplot2::ggplot_build(), computes
the banking ratio from one layer's fully resolved data (i.e. after
stats, position adjustments, and faceting have been applied), and
returns plot + coord_fixed(ratio = ...) (see ggplot2::coord_fixed()).
bank_plot( plot, method = c("ms", "as", "ao", "was"), cull = TRUE, layer = 1, ... )bank_plot( plot, method = c("ms", "as", "ao", "was"), cull = TRUE, layer = 1, ... )
plot |
A |
method, cull, ...
|
Passed to |
layer |
Integer. Which layer of |
Segments are never averaged across a group or facet panel boundary:
slopes are computed within each combination of group and
PANEL and then combined, so a line plot with multiple series (or
facets) is banked correctly rather than picking up spurious slopes
between the end of one line and the start of the next.
Note that ggplot2::coord_fixed() applies a single ratio to
every panel, so faceted plots are banked using the combined data from
all panels rather than a ratio tailored to each one individually.
The plot, with ggplot2::coord_fixed() added.
library("ggplot2") x <- seq_along(sunspot.year) y <- as.numeric(sunspot.year) p <- ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) + geom_line() bank_plot(p)library("ggplot2") x <- seq_along(sunspot.year) y <- as.numeric(sunspot.year) p <- ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) + geom_line() bank_plot(p)
A convenience wrapper around bank_slopes_multiscale() that
extracts y directly from an already-specified ggplot and
returns one copy of the plot per scale of interest, each with the
appropriate ggplot2::coord_fixed() applied. The result is the
small-multiples display used throughout Heer and Agrawala (2006): the same
data, banked to reveal trends at different frequencies.
bank_plot_multiscale( plot, method = c("ms", "as", "ao", "was"), cull = TRUE, layer = 1, ... )bank_plot_multiscale( plot, method = c("ms", "as", "ao", "was"), cull = TRUE, layer = 1, ... )
plot |
A |
method, cull, ...
|
Passed to |
layer |
Integer. Which layer of |
Multi-scale banking is defined on the frequency domain of a single series
sampled on a regular grid, so unlike bank_plot() this function
requires the chosen layer to hold exactly one series with evenly spaced
x values.
A named list of ggplot objects, one per retained
scale, in ascending order of frequency and named by frequency index.
Heer, Jeffrey and Maneesh Agrawala, 2006. "Multi-Scale Banking to 45." IEEE Transactions On Visualization And Computer Graphics 12(5).
bank_slopes_multiscale(), bank_plot()
library("ggplot2") y <- as.numeric(sunspot.year) p <- ggplot(data.frame(x = seq_along(y), y = y), aes(x = x, y = y)) + geom_line() # One plot per scale of interest, named by frequency index. plots <- bank_plot_multiscale(p) names(plots) ## Low-frequency trend across sunspot cycles plots[[1]] ## The individual 11-year cycles plots[[2]]library("ggplot2") y <- as.numeric(sunspot.year) p <- ggplot(data.frame(x = seq_along(y), y = y), aes(x = x, y = y)) + geom_line() # One plot per scale of interest, named by frequency index. plots <- bank_plot_multiscale(p) names(plots) ## Low-frequency trend across sunspot cycles plots[[1]] ## The individual 11-year cycles plots[[2]]
Calculate the optimal aspect ratio of a line graph by banking the
slopes to 45 degrees as suggested by W.S. Cleveland. This
maximizes the ability to visually differentiate differences in
slope. This function will calculate the optimal aspect ratio for
a line plot using any of the methods described in Heer and Agrawala
(2006). In their review of the methods they suggest using median
absolute slope banking ("ms"), which produces aspect ratios which
are generally the median of the various methods provided here.
bank_slopes( x, y, cull = TRUE, weight = NULL, method = c("ms", "as", "ao", "was"), ... )bank_slopes( x, y, cull = TRUE, weight = NULL, method = c("ms", "as", "ao", "was"), ... )
x |
A numeric vector of x values. |
y |
A numeric vector of y values. |
cull |
If |
weight |
|
method |
The banking method, one of:
|
... |
A number, the aspect ratio y / x, for use as ratio in
ggplot2::coord_fixed().
As written, all of these methods calculate the aspect ratio (x
/y), but bank_slopes() will return (y / x) to be compatible
with ggplot2::coord_fixed().
Median Absolute Slopes Banking
Let the aspect ratio be
then the median absolute slop banking is the
such that,
Let for ,
and . Then,
Average Absolute Slope Banking
Let the aspect ratio be .
then the mean absolute slope banking is the
such that,
Average Absolute Orientation Banking
Rather than averaging the slopes themselves, this method averages the
orientation (angle) of each segment, since perceived slope
differences are more closely related to angle than to the raw ratio
. Let
be the range-normalized slopes. Then is chosen such
that,
This has no closed-form solution and is found numerically with
stats::uniroot().
Weighted Average Absolute Orientation Banking
This is the weighted version of Average Absolute Orientation Banking from
Heer and Agrawala (2006). Each segment's absolute orientation is weighted
by its length in display space, so both the orientation and its weight
depend on . With as above and segment run
, is chosen such that,
This has no closed-form solution and is found numerically with
stats::uniroot().
All of these methods consider the entirety of the data at once, so they
accentuate local features and can obscure larger-scale trends. Heer and
Agrawala (2006) address this with multi-scale banking, which uses spectral
analysis to identify the frequency scales present in the data and banks
each one separately; see bank_slopes_multiscale() and
bank_plot_multiscale().
Cleveland, W. S., M. E. McGill, and R. McGill. The Shape Parameter of a Two-Variable Graph. Journal of the American Statistical Association, 83:289-300, 1988
Heer, Jeffrey and Maneesh Agrawala, 2006. 'Multi-Scale Banking to 45' IEEE Transactions On Visualization And Computer Graphics.
Cleveland, W. S. 1993. 'A Model for Studying Display Methods of Statistical Graphs.' Journal of Computational and Statistical Graphics.
Cleveland, W. S. 1994. The Elements of Graphing Data, Revised Edition.
lattice::banking(), bank_plot() to bank
a ggplot using its own data, and
bank_slopes_multiscale() to bank each frequency scale in the
data separately.
library("ggplot2") # Use the classic sunspot data from Cleveland's original paper x <- seq_along(sunspot.year) y <- as.numeric(sunspot.year) # Without banking m <- ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) + geom_line() m ## Using the default method, Median Absolute Slope ratio <- bank_slopes(x, y) m + coord_fixed(ratio = ratio) ## Average Absolute Slope m + coord_fixed(ratio = bank_slopes(x, y, method = "as")) ## Average Absolute Orientation m + coord_fixed(ratio = bank_slopes(x, y, method = "ao")) ## Weighted Average Absolute Slope: each segment is weighted by its run in ## x, so this only differs from "as" when x is not evenly spaced m + coord_fixed(ratio = bank_slopes(x, y, method = "was")) ## Culling removes slopes of 0 or Inf before banking, which matters when ## the data contains runs of repeated x or y values bank_slopes(x, y, cull = TRUE)library("ggplot2") # Use the classic sunspot data from Cleveland's original paper x <- seq_along(sunspot.year) y <- as.numeric(sunspot.year) # Without banking m <- ggplot(data.frame(x = x, y = y), aes(x = x, y = y)) + geom_line() m ## Using the default method, Median Absolute Slope ratio <- bank_slopes(x, y) m + coord_fixed(ratio = ratio) ## Average Absolute Slope m + coord_fixed(ratio = bank_slopes(x, y, method = "as")) ## Average Absolute Orientation m + coord_fixed(ratio = bank_slopes(x, y, method = "ao")) ## Weighted Average Absolute Slope: each segment is weighted by its run in ## x, so this only differs from "as" when x is not evenly spaced m + coord_fixed(ratio = bank_slopes(x, y, method = "was")) ## Culling removes slopes of 0 or Inf before banking, which matters when ## the data contains runs of repeated x or y values bank_slopes(x, y, cull = TRUE)
Compute a set of aspect ratios, one per frequency scale present in a
series, using the multi-scale banking algorithm of Heer and Agrawala
(2006). Single-scale banking (bank_slopes()) considers the
whole series at once, so it accentuates local features and can obscure
larger-scale trends. Multi-scale banking instead uses spectral analysis to
find the scales that carry real energy, low-pass filters the data to each
of those scales in turn, and banks the resulting trend curve, yielding one
aspect ratio per scale.
bank_slopes_multiscale( y, method = c("ms", "as", "ao", "was"), cull = TRUE, window = 3, sd = 1, threshold = NULL, scale_factor = 1.25 )bank_slopes_multiscale( y, method = c("ms", "as", "ao", "was"), cull = TRUE, window = 3, sd = 1, threshold = NULL, scale_factor = 1.25 )
y |
|
method, cull
|
Passed to |
window |
|
sd |
|
threshold |
|
scale_factor |
|
The procedure is Algorithm 1 of Heer and Agrawala (2006):
Take the discrete Fourier transform of y and form the power
spectrum from the squared coefficient magnitudes.
Smooth the spectrum by convolving it with a Gaussian kernel, since spectral energy tends to arrive in "clumps" containing local oscillation.
Threshold the smoothed spectrum. Contiguous runs above the threshold are collapsed to their highest-frequency bin, capturing the total contribution of that region of energy.
For each retained scale, low-pass filter y to remove all
higher frequencies and bank the resulting trend curve to 45 degrees using
bank_slopes().
Discard aspect ratios within scale_factor of the previous
retained ratio, since they would produce visually redundant charts.
The scale corresponding to the data in its entirety is always included.
Because the algorithm is defined on the frequency domain of y alone,
it assumes observations are evenly spaced in x; the banking of each
trend curve uses x = seq_along(y).
A tibble::tibble() with one row per retained scale, in
ascending order of frequency, and columns:
frequency: integer frequency index, i.e. the number of
times the trend repeats across the series.
ratio: numeric aspect ratio in the y / x sense
used by ggplot2::coord_fixed().
aspect_ratio: numeric the same value as width / height,
the convention in which the banking literature reports aspect ratios.
Heer, Jeffrey and Maneesh Agrawala, 2006. "Multi-Scale Banking to 45." IEEE Transactions On Visualization And Computer Graphics 12(5).
Cleveland, W. S. 1993. "A Model for Studying Display Methods of Statistical Graphs." Journal of Computational and Statistical Graphics.
bank_slopes() for single-scale banking, and
bank_plot_multiscale() to bank a ggplot at every scale.
library("ggplot2") # Sunspot activity, the classic example from Cleveland and from Heer and # Agrawala's Section 3.2.1. Spectral analysis identifies scales at frequency # indices 7, 10, 31 and 36, plus the data in its entirety; culling similar # aspect ratios leaves two charts worth drawing. y <- as.numeric(sunspot.year) bank_slopes_multiscale(y) # `ratio` is ready for coord_fixed(); `aspect_ratio` is the same value as # width / height, the convention used in the banking literature. scales <- bank_slopes_multiscale(y) m <- ggplot(data.frame(x = seq_along(y), y = y), aes(x = x, y = y)) + geom_line() ## The low-frequency trend: the oscillation of high points across cycles m + coord_fixed(ratio = scales$ratio[[1]]) ## The 11-year cycle: a steep onset followed by a more gradual decay m + coord_fixed(ratio = scales$ratio[[2]]) ## Raise the threshold to select fewer scales bank_slopes_multiscale(y, threshold = Inf) ## Any of the single-scale banking methods can be used for each scale bank_slopes_multiscale(y, method = "ao")library("ggplot2") # Sunspot activity, the classic example from Cleveland and from Heer and # Agrawala's Section 3.2.1. Spectral analysis identifies scales at frequency # indices 7, 10, 31 and 36, plus the data in its entirety; culling similar # aspect ratios leaves two charts worth drawing. y <- as.numeric(sunspot.year) bank_slopes_multiscale(y) # `ratio` is ready for coord_fixed(); `aspect_ratio` is the same value as # width / height, the convention used in the banking literature. scales <- bank_slopes_multiscale(y) m <- ggplot(data.frame(x = seq_along(y), y = y), aes(x = x, y = y)) + geom_line() ## The low-frequency trend: the oscillation of high points across cycles m + coord_fixed(ratio = scales$ratio[[1]]) ## The 11-year cycle: a steep onset followed by a more gradual decay m + coord_fixed(ratio = scales$ratio[[2]]) ## Raise the threshold to select fewer scales bank_slopes_multiscale(y, threshold = Inf) ## Any of the single-scale banking methods can be used for each scale bank_slopes_multiscale(y, method = "ao")
Color palettes from LibreOffice Calc. This palette has 12 values.
calc_pal()calc_pal()
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color calc:
scale_fill_calc()
library("scales") show_col(calc_pal()(12))library("scales") show_col(calc_pal()(12))
Shape palette based on the shapes used in LibreOffice Calc.
calc_shape_pal(unicode = FALSE)calc_shape_pal(unicode = FALSE)
unicode |
If |
A palette function. It takes the number of shapes n and returns an integer vector of n
shape (pch) codes, and can be used as the palette argument of
ggplot2::discrete_scale().
This palette supports seven values by default and thirteen with
unicode = TRUE. Six of Calc's thirteen symbols – the solid down,
left and right triangles, the bowtie, the hourglass and the four-pointed
star – have no base pch equivalent and are dropped rather than
approximated by a different shape. Restoring them with unicode = TRUE
needs a font covering Geometric Shapes, Dingbats and Miscellaneous
Mathematical Symbols-B; Noto Sans Symbols 2 is effectively the only free
font with the last of these.
Other shapes calc:
scale_shape_calc()
# The seven shapes with a font-independent equivalent. show_shapes(calc_shape_pal()(7)) ## Not run: # All thirteen, drawn from the device font. Needs a font covering Geometric # Shapes, Dingbats and Miscellaneous Mathematical Symbols-B, such as # Noto Sans Symbols 2. show_shapes(calc_shape_pal(unicode = TRUE)(13)) ## End(Not run)# The seven shapes with a font-independent equivalent. show_shapes(calc_shape_pal()(7)) ## Not run: # All thirteen, drawn from the device font. Needs a font covering Geometric # Shapes, Dingbats and Miscellaneous Mathematical Symbols-B, such as # Noto Sans Symbols 2. show_shapes(calc_shape_pal(unicode = TRUE)(13)) ## End(Not run)
150+ color palettes from canva.com. See canva_palettes.
canva_pal(palette = "Fresh and bright")canva_pal(palette = "Fresh and bright")
palette |
Palette name. See the names of canva_palettes for valid names. |
A function that takes a single value, the number of colors to use.
Other color canva:
scale_colour_canva()
require("ggplot2") require("tibble") if (require("purrr") && require("scales") && require("dplyr")) { canva_df <- map2_df( canva_palettes, names(canva_palettes), ~ tibble( colors = .x, .id = seq_along(colors), palette = .y ) ) ggplot( canva_df, aes( y = palette, x = .id, fill = colors ) ) + geom_raster() + scale_fill_identity(guide = FALSE) + theme_minimal() + theme( panel.grid = element_blank(), axis.text.x = element_blank() ) + labs(x = "", y = "") show_col(canva_pal("Fresh and bright")(4)) show_col(canva_pal("Cool blues")(4)) show_col(canva_pal("Modern and crisp")(4)) }require("ggplot2") require("tibble") if (require("purrr") && require("scales") && require("dplyr")) { canva_df <- map2_df( canva_palettes, names(canva_palettes), ~ tibble( colors = .x, .id = seq_along(colors), palette = .y ) ) ggplot( canva_df, aes( y = palette, x = .id, fill = colors ) ) + geom_raster() + scale_fill_identity(guide = FALSE) + theme_minimal() + theme( panel.grid = element_blank(), axis.text.x = element_blank() ) + labs(x = "", y = "") show_col(canva_pal("Fresh and bright")(4)) show_col(canva_pal("Cool blues")(4)) show_col(canva_pal("Modern and crisp")(4)) }
150 four-color palettes by the canva.com design school. These palettes were derived from photos and "impactful websites".
canva_palettescanva_palettes
A named list of character vectors.
The names are the palette names. The values of the character vectors
are hex colors, e.g. "#f98866".
Janie Kliever, 100 Brilliant Color Combinations and How to Apply Them to Your Designs, Canva.com, June 20, 2015.
Mary Stribley, Website Color Schemes: The Palettes of 50 Visually Impactful Websites to Inspire You, Canva.com, January 26, 2016.
Schwabish, Jonathan. 150+ Color Palettes for Excel, PolicyViz, January 12, 2017.
require("ggplot2") require("tibble") if (require("purrr") && require("scales") && require("dplyr")) { canva_df <- map2_df( canva_palettes, names(canva_palettes), ~ tibble( colors = .x, .id = seq_along(colors), palette = .y ) ) ggplot( canva_df, aes( y = palette, x = .id, fill = colors ) ) + geom_raster() + scale_fill_identity(guide = FALSE) + theme_minimal() + theme( panel.grid = element_blank(), axis.text.x = element_blank() ) + labs(x = "", y = "") show_col(canva_pal("Fresh and bright")(4)) show_col(canva_pal("Cool blues")(4)) show_col(canva_pal("Modern and crisp")(4)) }require("ggplot2") require("tibble") if (require("purrr") && require("scales") && require("dplyr")) { canva_df <- map2_df( canva_palettes, names(canva_palettes), ~ tibble( colors = .x, .id = seq_along(colors), palette = .y ) ) ggplot( canva_df, aes( y = palette, x = .id, fill = colors ) ) + geom_raster() + scale_fill_identity(guide = FALSE) + theme_minimal() + theme( panel.grid = element_blank(), axis.text.x = element_blank() ) + labs(x = "", y = "") show_col(canva_pal("Fresh and bright")(4)) show_col(canva_pal("Cool blues")(4)) show_col(canva_pal("Modern and crisp")(4)) }
This function was deprecated because unicode glyphs used for the circles vary in size, making them unusable for plotting.
Shape palette with circles varying by amount of fill. This uses the set of 3 circle fill values in Lewandowsky and Spence (1989): solid, hollow, half-filled, with two additional fill amounts: three-quarters, and one-quarter.
This palette supports up to five values.
circlefill_shape_pal()circlefill_shape_pal()
A palette function. It takes the number of shapes n and returns an integer vector of n
shape (pch) codes, and can be used as the palette argument of
ggplot2::discrete_scale().
Lewandowsky, Stephan and Ian Spence (1989) "Discriminating Strata in Scatterplots", Journal of the American Statistical Association, https://www.jstor.org/stable/2289649
Other shapes:
cleveland_shape_pal(),
scale_shape_circlefill(),
scale_shape_cleveland(),
scale_shape_tremmel(),
tremmel_shape_pal()
circlefill_shape_pal()(3)circlefill_shape_pal()(3)
Shape palettes for overlapping and non-overlapping points.
cleveland_shape_pal(overlap = TRUE, unicode = FALSE)cleveland_shape_pal(overlap = TRUE, unicode = FALSE)
overlap |
|
unicode |
If |
A palette function. It takes the number of shapes n and returns an integer vector of n
shape (pch) codes, and can be used as the palette argument of
ggplot2::discrete_scale().
In the Elements of Graphing Data, W.S. Cleveland suggests two shape palettes for scatter plots: one for overlapping data and another for non-overlapping data. The symbols for overlapping data rely on pattern discrimination, while the symbols for non-overlapping data vary the amount of fill.
Following Tremmel (1995), the circle with a vertical line is replaced by an encircled plus sign.
cleveland_shape_pal(overlap = TRUE) supports four values on either
branch.
cleveland_shape_pal(overlap = FALSE) supports three values by
default and five with unicode = TRUE. Its five source symbols encode
fill fraction, which base pch cannot express, so the two
partially filled circles are dropped rather than approximated by a
different shape. To encode a proportion, map alpha or fill
instead; to restore the five glyphs, use unicode = TRUE with a font
that covers Mathematical Operators, such as STIX Two Text.
The truncation is arguably an improvement. Tremmel (1995) Experiment 2 tested exactly this five-symbol set and found the fill-graded circles the worst performers measured, with the encircled plus and encircled dot the slowest pair and the one producing the most errors. The three shapes that survive are the better-separating subset.
Cleveland WS. The Elements of Graphing Data. Revised Edition. Hobart Press, Summit, NJ, 1994, pp. 154-164, 234-239.
Tremmel, Lothar, (1995) "The Visual Separability of Plotting Symbols in Scatterplots", Journal of Computational and Graphical Statistics, https://www.jstor.org/stable/1390760
Other shapes:
circlefill_shape_pal(),
scale_shape_circlefill(),
scale_shape_cleveland(),
scale_shape_tremmel(),
tremmel_shape_pal()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + facet_wrap(~am) + theme_bw() # overlapping symbol palette p + scale_shape_cleveland() # non-overlapping symbol palette p + scale_shape_cleveland(overlap = FALSE)library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + facet_wrap(~am) + theme_bw() # overlapping symbol palette p + scale_shape_cleveland() # non-overlapping symbol palette p + scale_shape_cleveland(overlap = FALSE)
An eight-color colorblind safe qualitative discrete palette.
scale_colour_colorblind() is
deprecated in favor of scale_colour_colourblind() and
scale_color_colorblind().
colorblind_pal(black = TRUE) colourblind_pal(black = TRUE) scale_colour_colourblind(black = TRUE, ...) scale_colour_colorblind(black = TRUE, ...) scale_color_colorblind(black = TRUE, ...) scale_fill_colourblind(black = TRUE, ...) scale_fill_colorblind(black = TRUE, ...)colorblind_pal(black = TRUE) colourblind_pal(black = TRUE) scale_colour_colourblind(black = TRUE, ...) scale_colour_colorblind(black = TRUE, ...) scale_color_colorblind(black = TRUE, ...) scale_fill_colourblind(black = TRUE, ...) scale_fill_colorblind(black = TRUE, ...)
black |
If |
... |
Arguments passed on to
|
colorblind_pal() and colourblind_pal() return a palette function that takes the number of
colors n and returns a character vector of n hex colors. The scale_*() functions
return a ggplot2 scale object.
Chang, W. "Cookbook for R"
https://jfly.iam.u-tokyo.ac.jp/color/
The dichromat package, scales::dichromat_pal(),
and scale_color_tableau() for other colorblind palettes.
library("ggplot2") library("scales") show_col(colorblind_pal()(8)) show_col(colorblind_pal(black = FALSE)(7)) p <- ggplot(mtcars) + geom_point(aes( x = wt, y = mpg, colour = factor(gear) )) + facet_wrap(~am) p + theme_igray() + scale_colour_colourblind()library("ggplot2") library("scales") show_col(colorblind_pal()(8)) show_col(colorblind_pal(black = FALSE)(7)) p <- ggplot(mtcars) + geom_point(aes( x = wt, y = mpg, colour = factor(gear) )) + facet_wrap(~am) p + theme_igray() + scale_colour_colourblind()
The classic The Economist chart palette: blues, grays, and greens, chosen and ordered for the number of colors requested. Red is not included in these palettes; The Economist reserves it to mark important data.
economist_pal(fill = TRUE)economist_pal(fill = TRUE)
fill |
If |
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color economist:
economist_seq_pal(),
scale_colour_economist(),
scale_colour_economist_c()
library("scales") show_col(economist_pal()(6)) ## fill palette show_col(economist_pal(fill = TRUE)(6))library("scales") show_col(economist_pal()(6)) ## fill palette show_col(economist_pal(fill = TRUE)(6))
The "equal lightness colour scales" of The Economist visual
styleguide (v1.2, 4 May 2017): six ordered steps for each of nine hues,
running darkest to lightest. Use them for ordered data. They come from
the paper's 2017 chart design, not the classic design of
economist_pal() and theme_economist().
economist_seq_pal(hue = "blue") economist_gradient_pal(hue = "blue")economist_seq_pal(hue = "blue") economist_gradient_pal(hue = "blue")
hue |
A string, the hue of the color scale. One of |
economist_seq_pal() returns the six steps themselves, for
discrete ordered data. economist_gradient_pal() interpolates
between them, for continuous data.
economist_seq_pal() returns a palette function that takes the number of colors n and
returns the first n of the six hex colors for hue, for use with
ggplot2::discrete_scale(). economist_gradient_pal() returns a palette function that
takes a numeric vector x of values between 0 and 1 and returns hex colors interpolated between
those steps, for use with ggplot2::continuous_scale().
Other color economist:
economist_pal(),
scale_colour_economist(),
scale_colour_economist_c()
library("scales") # the six steps of one hue, darkest first show_col(economist_seq_pal("blue")(6)) show_col(economist_seq_pal("red")(6)) # interpolated for continuous data show_col(economist_gradient_pal("green")(seq(0, 1, length.out = 10)))library("scales") # the six steps of one hue, darkest first show_col(economist_seq_pal("blue")(6)) show_col(economist_seq_pal("red")(6)) # interpolated for continuous data show_col(economist_gradient_pal("green")(seq(0, 1, length.out = 10)))
Color palettes used by current versions of Microsoft Office and Excel.
excel_new_pal(theme = "Office")excel_new_pal(theme = "Office")
theme |
The name of the Office theme or color theme
(not to be confused with ggplot2 themes) from which to derive the color
palette. Available themes include:
|
In 2023 Microsoft replaced the long-standing Office theme with a new
default and renamed the old one. The default here, "Office", is the
current palette; "Office 2013" is the palette Excel used from 2013
until 2022. The former ggthemes names "Office Theme" and
"Office 2007-2010" still work, and select "Office 2013" and
"Office 2007" respectively.
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color excel:
excel_pal(),
scale_colour_excel_new(),
scale_fill_excel()
library("scales") for (i in names(ggthemes::ggthemes_data$excel$themes)) { show_col(excel_new_pal(theme = i)(6)) }library("scales") for (i in names(ggthemes::ggthemes_data$excel$themes)) { show_col(excel_new_pal(theme = i)(6)) }
The color palettes used in Microsoft Excel 97 (and up until Excel 2007). Use this for that classic ugly look and feel. For ironic purposes only. 3D bars and pies not included. Please never use this color palette.
excel_pal(line = TRUE)excel_pal(line = TRUE)
line |
If |
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color excel:
excel_new_pal(),
scale_colour_excel_new(),
scale_fill_excel()
library("scales") show_col(excel_pal()(7)) show_col(excel_pal(line = FALSE)(7))library("scales") show_col(excel_pal()(7)) show_col(excel_pal(line = FALSE)(7))
This function returns pretty axis breaks that always include the extreme values of the data. This works by calling the extended Wilkinson algorithm (Talbot et al., 2010), constrained to solutions interior to the data range. Then, the minimum and maximum labels are moved to the minimum and maximum of the data range.
extended_range_breaks_( dmin, dmax, n = 5, Q = c(1, 5, 2, 2.5, 4, 3), w = c(0.25, 0.2, 0.5, 0.05) ) extended_range_breaks(n = 5, ...)extended_range_breaks_( dmin, dmax, n = 5, Q = c(1, 5, 2, 2.5, 4, 3), w = c(0.25, 0.2, 0.5, 0.05) ) extended_range_breaks(n = 5, ...)
dmin |
Minimum of the data range. |
dmax |
Maximum of the data range. |
n |
Desired number of breaks. |
Q |
Set of nice numbers. |
w |
Weights applied to the four optimization components (simplicity, coverage, density, and legibility). |
... |
Other arguments passed to |
extended_range_breaks_() implements the algorithm and returns the break values.
extended_range_breaks() uses the conventions of the scales package, and returns a function.
Note that ggplot2 hands a breaks function the expanded scale limits, not the data
range. Passing extended_range_breaks() directly to breaks therefore places the
end labels at the panel edges rather than at the extremes of the data. To label the extremes,
which is what pairs with geom_rangeframe(), apply the function to the data
instead: scale_x_continuous(breaks = extended_range_breaks()(mtcars$wt)).
For extended_range_breaks_, the vector of axis label locations.
For extended_range_breaks, a function which takes a single argument, a vector of data, and returns
the vector of axis label locations.
Justin Talbot [email protected], Jeffrey B. Arnold, Baptiste Auguie
Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes, InfoVis 2010.
Other tufte:
geom_rangeframe(),
geom_tufteboxplot(),
theme_tufte()
# Pretty breaks that always include the extremes of the data extended_range_breaks_(min(mtcars$wt), max(mtcars$wt)) # A function, in the style of the scales package extended_range_breaks()(mtcars$wt) library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + geom_rangeframe() + scale_x_continuous(breaks = extended_range_breaks()(mtcars$wt)) + scale_y_continuous(breaks = extended_range_breaks()(mtcars$mpg)) + theme_tufte()# Pretty breaks that always include the extremes of the data extended_range_breaks_(min(mtcars$wt), max(mtcars$wt)) # A function, in the style of the scales package extended_range_breaks()(mtcars$wt) library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + geom_rangeframe() + scale_x_continuous(breaks = extended_range_breaks()(mtcars$wt)) + scale_y_continuous(breaks = extended_range_breaks()(mtcars$mpg)) + theme_tufte()
Qualitative color palettes from Stephen Few (2012)
Show Me the Numbers. There are three palettes:
Light, Medium, and Dark. Each palette comprises nine colors:
gray, blue, orange, green, pink, brown, purple, yellow, red.
For n = 1, gray is used. For n > 1, the eight non-gray
colors are used.
few_pal(palette = "Medium")few_pal(palette = "Medium")
palette |
One of |
Use the light palette for filled areas, such as bar charts. Use the medium palette for points and lines. Use the dark palette for highlighting specific points or for small and thin lines and points.
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Few, S. (2012) Show Me the Numbers: Designing Tables and Graphs to Enlighten. 2nd edition. Analytics Press.
"Practical Rules for Using Color in Charts".
Other color few:
scale_colour_few()
library("scales") show_col(few_pal()(7)) show_col(few_pal("Dark")(7)) show_col(few_pal("Light")(7))library("scales") show_col(few_pal()(7)) show_col(few_pal("Dark")(7)) show_col(few_pal("Light")(7))
Shape palette from Stephen Few's "Show Me the Numbers". The shape palette consists of five shapes: circle, square, triangle, plus, times.
few_shape_pal()few_shape_pal()
A palette function. It takes the number of shapes n and returns an integer vector of n
shape (pch) codes, and can be used as the palette argument of
ggplot2::discrete_scale().
Few, S. (2012) Show Me the Numbers: Designing Tables and Graphs to Enlighten, Analytics Press, p. 208.
Other shapes few:
scale_shape_few()
few_shape_pal()(5) show_shapes(few_shape_pal()(5))few_shape_pal()(5) show_shapes(few_shape_pal()(5))
The standard three-color FiveThirtyEight palette for line plots comprises blue, red, and green.
fivethirtyeight_pal()fivethirtyeight_pal()
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color fivethirtyeight:
scale_colour_fivethirtyeight()
library("scales") show_col(fivethirtyeight_pal()(3))library("scales") show_col(fivethirtyeight_pal()(3))
Color palettes from Google Docs. This palette includes 20 colors.
gdocs_pal()gdocs_pal()
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color gdocs:
scale_fill_gdocs()
library("scales") show_col(gdocs_pal()(24))library("scales") show_col(gdocs_pal()(24))
Axis lines which extend to the maximum and minimum of the plotted data.
geom_rangeframe( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., sides = "bl", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_rangeframe( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., sides = "bl", na.rm = FALSE, 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
|
sides |
A string that controls which sides of the plot the frames appear on.
It can be set to a string containing any of |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
This should be used with coord_cartesian(clip="off") in order to
correctly draw the lines.
Secondary axes (ggplot2::sec_axis()) only relabel the
existing axis; they do not introduce a separate data range. Because of
this, sides = "trbl" already draws correctly-positioned frames on
the top/right edges of a panel that has a secondary axis – there is no
separate "secondary" range for geom_rangeframe() to draw against.
A ggplot2 layer.
colour
size
linetype
alpha
Tufte, Edward R. (2001) The Visual Display of Quantitative Information, Chapter 6.
Other geom tufte:
geom_tufteboxplot()
Other tufte:
extended_range_breaks_(),
geom_tufteboxplot(),
theme_tufte()
library("ggplot2") ggplot(mtcars, aes(wt, mpg)) + geom_point() + geom_rangeframe() + coord_cartesian(clip = "off") + theme_tufte() # In the example above, # `coord_cartesian(clip="off")`` ensures that the full width of the line is drawn. # if you know a better way to fix this, # please open an issue or PR on github https://github.com/jrnold/ggthemes/issue # sides = "trbl" also works with a secondary axis: the secondary axis only # relabels the existing scale, so the frame is still correctly positioned. ggplot(mtcars, aes(wt, mpg)) + geom_point() + geom_rangeframe(sides = "trbl") + scale_y_continuous(sec.axis = sec_axis(~ . * 0.4251, name = "km/L")) + coord_cartesian(clip = "off") + theme_tufte()library("ggplot2") ggplot(mtcars, aes(wt, mpg)) + geom_point() + geom_rangeframe() + coord_cartesian(clip = "off") + theme_tufte() # In the example above, # `coord_cartesian(clip="off")`` ensures that the full width of the line is drawn. # if you know a better way to fix this, # please open an issue or PR on github https://github.com/jrnold/ggthemes/issue # sides = "trbl" also works with a secondary axis: the secondary axis only # relabels the existing scale, so the frame is still correctly positioned. ggplot(mtcars, aes(wt, mpg)) + geom_point() + geom_rangeframe(sides = "trbl") + scale_y_continuous(sec.axis = sec_axis(~ . * 0.4251, name = "km/L")) + coord_cartesian(clip = "off") + theme_tufte()
Edward Tufte's revisions of the box plot as described in The Visual Display of Quantitative Information. This function provides several box plot variants:
A point indicating the median, a gap indicating the interquartile range, and lines for whiskers.
An offset line indicating the interquartile range and a gap indicating the median.
A line indicating the interquartile range, a gap indicating the median, and points indicating the minimum and maximum values.
A wide line indicating the interquartile range, a gap indicating the median, and lines indicating the minimum and maximum.
geom_tufteboxplot( mapping = NULL, data = NULL, stat = "fivenumber", position = "dodge", outlier.colour = "black", outlier.shape = 19, outlier.size = 1.5, outlier.stroke = 0.5, voffset = 0.01, hoffset = 0.005, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, median.type = "point", whisker.type = "line", ... )geom_tufteboxplot( mapping = NULL, data = NULL, stat = "fivenumber", position = "dodge", outlier.colour = "black", outlier.shape = 19, outlier.size = 1.5, outlier.stroke = 0.5, voffset = 0.01, hoffset = 0.005, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, median.type = "point", whisker.type = "line", ... )
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, as a string. The default ( |
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
|
outlier.colour |
Color of outlying points. |
outlier.shape |
Shape of outlying points. |
outlier.size |
Size of outlying points. |
outlier.stroke |
Stroke width of outlying points. |
voffset |
Controls the size of the gap in the line representing the
median when |
hoffset |
Controls how much the interquartile line is offset from the
whiskers when |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
median.type |
How to represent the median, one of:
|
whisker.type |
How to represent the whiskers, one of:
|
... |
Other arguments passed on to
|
A ggplot2 layer.
x (required)
y (required)
colour
size
linewidth
linetype
shape
fill
alpha
Tufte, Edward R. (2001) The Visual Display of Quantitative Information, Chapter 6.
McGill, R., Tukey, J. W. and Larsen, W. A. (1978) Variations of box plots. The American Statistician 32, 12-16.
Other geom tufte:
geom_rangeframe()
Other tufte:
extended_range_breaks_(),
geom_rangeframe(),
theme_tufte()
library("ggplot2") p <- ggplot(mtcars, aes(factor(cyl), mpg)) # with a point for the median and lines for whiskers p + geom_tufteboxplot() # with a line for the interquartile range and points for whiskers p + geom_tufteboxplot(median.type = "line", whisker.type = "point", hoffset = 0) # with a wide line for the interquartile range and lines for whiskers. # `width` scales the median line but is also the box width, so use # position = "identity" to stop position_dodge() warning about overlaps. p + geom_tufteboxplot(median.type = "line", hoffset = 0, width = 3, position = "identity") # with an offset line for the interquartile range and lines for whiskers p + geom_tufteboxplot(median.type = "line") # combined with theme_tufte p + geom_tufteboxplot() + theme_tufte() + theme(axis.ticks.x = element_blank()) # traditional boxplot with whiskers only out to 1.5 IQR, outlier points p + geom_tufteboxplot(stat = "boxplot", outlier.shape = 5)library("ggplot2") p <- ggplot(mtcars, aes(factor(cyl), mpg)) # with a point for the median and lines for whiskers p + geom_tufteboxplot() # with a line for the interquartile range and points for whiskers p + geom_tufteboxplot(median.type = "line", whisker.type = "point", hoffset = 0) # with a wide line for the interquartile range and lines for whiskers. # `width` scales the median line but is also the box width, so use # position = "identity" to stop position_dodge() warning about overlaps. p + geom_tufteboxplot(median.type = "line", hoffset = 0, width = 3, position = "identity") # with an offset line for the interquartile range and lines for whiskers p + geom_tufteboxplot(median.type = "line") # combined with theme_tufte p + geom_tufteboxplot() + theme_tufte() + theme(axis.ticks.x = element_blank()) # traditional boxplot with whiskers only out to 1.5 IQR, outlier points p + geom_tufteboxplot(stat = "boxplot", outlier.shape = 5)
ggthemes_data is a list of the colors, shapes, and other values used in
the themes and palettes of this package. Its structure is internal and
subject to change.
ggthemes_dataggthemes_data
A list object.
ggthemes_data$stata$colors$names spans both generations of Stata's
named colors: the classic set plus the gs0–gs16 gray scale,
and the stc1–stc15 colors added in Stata 18. See
stata_pal().
Colors, shapes and linetypes are stored with the theme they belong to. The
Package data
article on the package website draws every one of them. ggthemes_data
contains no fonts: themes set their typefaces in code.
library("scales") ## One element per theme names(ggthemes_data) ## Colors are stored as tables of names and hex values ... ggthemes_data$fivethirtyeight show_col(ggthemes_data$fivethirtyeight$value) ## ... as plain hex vectors ... show_col(ggthemes_data$manyeyes) ## ... or once per number of colors show_col(ggthemes_data$solarized$palettes$blue[[4]]) ## Shapes give a base R symbol (pch), where there is one, and the Unicode ## character they were transcribed from stata_shapes <- ggthemes_data$stata$shapes stata_shapes[c("symbolstyle", "character", "pch")] show_shapes(stata_shapes$pch) ## Linetypes are dash patterns show_linetypes(ggthemes_data$stata$linetypes[1:10])library("scales") ## One element per theme names(ggthemes_data) ## Colors are stored as tables of names and hex values ... ggthemes_data$fivethirtyeight show_col(ggthemes_data$fivethirtyeight$value) ## ... as plain hex vectors ... show_col(ggthemes_data$manyeyes) ## ... or once per number of colors show_col(ggthemes_data$solarized$palettes$blue[[4]]) ## Shapes give a base R symbol (pch), where there is one, and the Unicode ## character they were transcribed from stata_shapes <- ggthemes_data$stata$shapes stata_shapes[c("symbolstyle", "character", "pch")] show_shapes(stata_shapes$pch) ## Linetypes are dash patterns show_linetypes(ggthemes_data$stata$linetypes[1:10])
Highcharts uses many different color palettes in its plots. This collects the palettes shipped with Highcharts 13, plus the default Highcharts used before v11.
hc_pal(palette = "default")hc_pal(palette = "default")
palette |
A string, the name of the Highcharts palette to use.
One of |
"default" and "default_dark" are the light- and dark-mode
forms of the palette Highcharts has used by default since v11.0.0; they
differ only in positions 2 and 3. "classic" is the default
Highcharts used from v5.0.0 through v10.x. The remaining palettes come
from the themes bundled with Highcharts.
Note that "avocado" and "sunset" have only four colors.
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color hc:
scale_colour_hc()
hc_pal()(6) scales::show_col(hc_pal("darkunica")(4))hc_pal()(6) scales::show_col(hc_pal("darkunica")(4))
Color palettes used by charts in Apple Numbers. Each palette provides the six series colors that Numbers assigns to a chart's data series, in order.
numbers_pal(palette = "Classic")numbers_pal(palette = "Classic")
palette |
Palette name. One of
|
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color numbers:
scale_fill_numbers()
library("scales") show_col(numbers_pal()(6)) show_col(numbers_pal("Spectrum")(6))library("scales") show_col(numbers_pal()(6)) show_col(numbers_pal("Spectrum")(6))
The pander package ships with a default colorblind and printer-friendly color palette borrowed from https://jfly.iam.u-tokyo.ac.jp/color/.
palette_pander(n, random_order = FALSE)palette_pander(n, random_order = FALSE)
n |
Number of colors. This palette supports up to eight colors. |
random_order |
Whether to shuffle the palette randomly before rendering each plot. |
A character vector of n hex colors, recycled if n exceeds the number of colors available.
Unlike the other *_pal() functions, this is itself the palette function.
Other color pander:
scale_color_pander()
palette_pander(8) # the same colors in a random order palette_pander(8, random_order = TRUE)palette_pander(8) # the same colors in a random order palette_pander(8, random_order = TRUE)
ptol_pal() was deprecated in ggthemes 7.0.0. Use the
khroma package instead, which
tracks Paul Tol's color schemes as he revises them.
This palette is the 12-color qualitative scheme from Tol's 2012 technical
note, and has not followed the revisions he has made since. His current
schemes are at https://sronpersonalpages.nl/~pault/; the closest successor
to this palette is khroma::colour("muted").
Qualitative color palettes from Paul Tol, "Colour Schemes".
ptol_pal()ptol_pal()
Incorporation of the palette into an R package was originally inspired by Peter Carl's Paul Tol 21 Gun Salute
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Paul Tol. 2012. "Colour Schemes." SRON Technical Note, SRON/EPS/TN/09-002. https://sronpersonalpages.nl/~pault/data/colourschemes.pdf
Other color ptol:
scale_colour_ptol()
library("scales") show_col(ptol_pal()(6)) show_col(ptol_pal()(4)) show_col(ptol_pal()(12))library("scales") show_col(ptol_pal()(6)) show_col(ptol_pal()(4)) show_col(ptol_pal()(12))
The pander package ships with a default colorblind and printer-friendly color palette borrowed from https://jfly.iam.u-tokyo.ac.jp/color/.
scale_color_pander(...) scale_colour_pander(...) scale_fill_pander(...)scale_color_pander(...) scale_colour_pander(...) scale_fill_pander(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color pander:
palette_pander()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_pander()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_pander()
Color scale for canva.com color palettes described in canva_palettes.
scale_colour_canva(..., palette = "Fresh and bright") scale_color_canva(..., palette = "Fresh and bright") scale_fill_canva(..., palette = "Fresh and bright")scale_colour_canva(..., palette = "Fresh and bright") scale_color_canva(..., palette = "Fresh and bright") scale_fill_canva(..., palette = "Fresh and bright")
... |
Arguments passed to |
palette |
Palette name. See the names of canva_palettes for valid names. |
A ggplot2 scale object.
Other color canva:
canva_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_canva()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_canva()
Color scales using the colors in the Economist graphics.
scale_colour_economist(...) scale_color_economist(...) scale_fill_economist(...)scale_colour_economist(...) scale_color_economist(...) scale_fill_economist(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
theme_economist() for examples.
Other color economist:
economist_pal(),
economist_seq_pal(),
scale_colour_economist_c()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_economist()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_economist()
Color scales built from the equal-lightness color scales of The
Economist visual styleguide (v1.2, 4 May 2017); see
economist_seq_pal().
The _c scales are continuous; the _ordinal scales are
discrete, for ordered factors. See scale_colour_economist()
for the unordered categorical scales.
scale_colour_economist_c(hue = "blue", ..., guide = "colourbar") scale_color_economist_c(hue = "blue", ..., guide = "colourbar") scale_fill_economist_c(hue = "blue", ..., guide = "colourbar") scale_colour_economist_ordinal(hue = "blue", ...) scale_color_economist_ordinal(hue = "blue", ...) scale_fill_economist_ordinal(hue = "blue", ...)scale_colour_economist_c(hue = "blue", ..., guide = "colourbar") scale_color_economist_c(hue = "blue", ..., guide = "colourbar") scale_fill_economist_c(hue = "blue", ..., guide = "colourbar") scale_colour_economist_ordinal(hue = "blue", ...) scale_color_economist_ordinal(hue = "blue", ...) scale_fill_economist_ordinal(hue = "blue", ...)
hue |
A string, the hue of the color scale. One of |
... |
Other arguments passed on to the underlying scale. |
guide |
A function used to create a guide or its name. See
|
A ggplot2 scale object.
Other color economist:
economist_pal(),
economist_seq_pal(),
scale_colour_economist()
library("ggplot2") # Continuous scale ggplot(mtcars, aes(x = wt, y = mpg, colour = disp)) + geom_point(size = 3) + scale_colour_economist_c(hue = "blue") # Ordinal (discrete) scale for an ordered factor ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl, ordered = TRUE))) + geom_point(size = 3) + scale_colour_economist_ordinal(hue = "red")library("ggplot2") # Continuous scale ggplot(mtcars, aes(x = wt, y = mpg, colour = disp)) + geom_point(size = 3) + scale_colour_economist_c(hue = "blue") # Ordinal (discrete) scale for an ordered factor ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl, ordered = TRUE))) + geom_point(size = 3) + scale_colour_economist_ordinal(hue = "red")
Discrete color scales used in current versions of Microsoft Office and Excel.
scale_colour_excel_new(theme = "Office", ...) scale_color_excel_new(theme = "Office", ...) scale_fill_excel_new(theme = "Office", ...)scale_colour_excel_new(theme = "Office", ...) scale_color_excel_new(theme = "Office", ...) scale_fill_excel_new(theme = "Office", ...)
theme |
The name of the Office theme or color theme
(not to be confused with ggplot2 themes) from which to derive the color
palette. Available themes include:
|
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color excel:
excel_new_pal(),
excel_pal(),
scale_fill_excel()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_excel_new() + scale_colour_excel_new()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_excel_new() + scale_colour_excel_new()
See few_pal().
scale_colour_few(palette = "Medium", ...) scale_color_few(palette = "Medium", ...) scale_fill_few(palette = "Light", ...)scale_colour_few(palette = "Medium", ...) scale_color_few(palette = "Medium", ...) scale_fill_few(palette = "Light", ...)
palette |
One of |
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color few:
few_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_few("Dark")library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_few("Dark")
Color scales using the colors in the FiveThirtyEight graphics.
scale_colour_fivethirtyeight(...) scale_color_fivethirtyeight(...) scale_fill_fivethirtyeight(...)scale_colour_fivethirtyeight(...) scale_color_fivethirtyeight(...) scale_fill_fivethirtyeight(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
theme_fivethirtyeight() for examples.
Other color fivethirtyeight:
fivethirtyeight_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_fivethirtyeight()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_fivethirtyeight()
Continuous color scales using the sequential color palettes in Tableau.
See scale_colour_tableau() for Tableau discrete color scales,
and scale_colour_gradient2_tableau() for diverging color
scales.
scale_colour_gradient_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_fill_gradient_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_color_gradient_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_color_continuous_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_colour_continuous_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_fill_continuous_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" )scale_colour_gradient_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_fill_gradient_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_color_gradient_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_color_continuous_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_colour_continuous_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" ) scale_fill_continuous_tableau( palette = "Blue", ..., na.value = "grey50", guide = "colourbar" )
palette |
Palette name. For each
|
... |
Arguments passed to |
na.value |
Colour to use for missing values |
guide |
Type of legend. Use |
A ggplot2 scale object.
Other color tableau:
scale_colour_gradient2_tableau(),
scale_colour_tableau(),
tableau_color_pal(),
tableau_gradient_pal()
library("ggplot2") df <- data.frame( x = runif(100), y = runif(100), z1 = rnorm(100), z2 = abs(rnorm(100)) ) p <- ggplot(df, aes(x, y)) + geom_point(aes(colour = z2)) + theme_igray() palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["ordered-sequential"]] for (palette in head(names(palettes))) { print(p + scale_colour_gradient_tableau(palette) + ggtitle(palette)) }library("ggplot2") df <- data.frame( x = runif(100), y = runif(100), z1 = rnorm(100), z2 = abs(rnorm(100)) ) p <- ggplot(df, aes(x, y)) + geom_point(aes(colour = z2)) + theme_igray() palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["ordered-sequential"]] for (palette in head(names(palettes))) { print(p + scale_colour_gradient_tableau(palette) + ggtitle(palette)) }
Continuous color scales using the diverging color scales in Tableau.
See scale_colour_tableau() for Tableau discrete color scales,
and scale_colour_gradient_tableau() for sequential color scales.
scale_colour_gradient2_tableau( palette = "Orange-Blue Diverging", ..., midpoint = 0, na.value = "grey50", guide = "colourbar" ) scale_fill_gradient2_tableau( palette = "Orange-Blue Diverging", ..., midpoint = 0, na.value = "grey50", guide = "colourbar" ) scale_color_gradient2_tableau( palette = "Orange-Blue Diverging", ..., midpoint = 0, na.value = "grey50", guide = "colourbar" )scale_colour_gradient2_tableau( palette = "Orange-Blue Diverging", ..., midpoint = 0, na.value = "grey50", guide = "colourbar" ) scale_fill_gradient2_tableau( palette = "Orange-Blue Diverging", ..., midpoint = 0, na.value = "grey50", guide = "colourbar" ) scale_color_gradient2_tableau( palette = "Orange-Blue Diverging", ..., midpoint = 0, na.value = "grey50", guide = "colourbar" )
palette |
Palette name. For each
|
... |
Arguments passed to |
midpoint |
The data value that corresponds to the middle color of the diverging palette. |
na.value |
Colour to use for missing values |
guide |
Type of legend. Use |
A ggplot2 scale object.
Other color tableau:
scale_colour_gradient_tableau(),
scale_colour_tableau(),
tableau_color_pal(),
tableau_gradient_pal()
library("ggplot2") df <- data.frame( x = runif(100), y = runif(100), z1 = rnorm(100), z2 = abs(rnorm(100)) ) p <- ggplot(df, aes(x, y)) + geom_point(aes(colour = z2)) palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["ordered-diverging"]] for (palette in head(names(palettes))) { print(p + scale_colour_gradient2_tableau(palette) + ggtitle(palette)) } # If you need to reverse a palette, use a transformation p + scale_colour_gradient2_tableau(trans = "reverse")library("ggplot2") df <- data.frame( x = runif(100), y = runif(100), z1 = rnorm(100), z2 = abs(rnorm(100)) ) p <- ggplot(df, aes(x, y)) + geom_point(aes(colour = z2)) palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["ordered-diverging"]] for (palette in head(names(palettes))) { print(p + scale_colour_gradient2_tableau(palette) + ggtitle(palette)) } # If you need to reverse a palette, use a transformation p + scale_colour_gradient2_tableau(trans = "reverse")
Color and fill scales which use the palettes in
hc_pal() and are meant for use with
theme_hc().
scale_colour_hc(palette = "default", ...) scale_color_hc(palette = "default", ...) scale_fill_hc(palette = "default", ...)scale_colour_hc(palette = "default", ...) scale_color_hc(palette = "default", ...) scale_fill_hc(palette = "default", ...)
palette |
A string, the name of the Highcharts palette to use.
One of |
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color hc:
hc_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_hc(palette = "darkunica")library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_hc(palette = "darkunica")
These scales were deprecated in ggthemes 7.0.0. Use the khroma package instead, which tracks Paul Tol's color schemes as he revises them.
They draw the 12-color qualitative scheme from Tol's 2012 technical note,
and have not followed the revisions he has made since. His current schemes
are at https://sronpersonalpages.nl/~pault/; the closest successor is
khroma::scale_colour_muted().
See ptol_pal(). These palettes support up to 12 values.
scale_colour_ptol(...) scale_color_ptol(...) scale_fill_ptol(...)scale_colour_ptol(...) scale_color_ptol(...) scale_fill_ptol(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color ptol:
ptol_pal()
library("ggplot2") p2 <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point() + geom_smooth(method = "lm", se = FALSE) + scale_color_ptol("cyl") + theme_minimal() + ggtitle("Cars") ggplot(diamonds, aes(x = clarity, fill = cut)) + geom_bar() + scale_fill_ptol() + theme_minimal()library("ggplot2") p2 <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point() + geom_smooth(method = "lm", se = FALSE) + scale_color_ptol("cyl") + theme_minimal() + ggtitle("Cars") ggplot(diamonds, aes(x = clarity, fill = cut)) + geom_bar() + scale_fill_ptol() + theme_minimal()
See stata_pal() for details.
scale_colour_stata(scheme = NULL, ...) scale_fill_stata(scheme = NULL, ...) scale_color_stata(scheme = NULL, ...)scale_colour_stata(scheme = NULL, ...) scale_fill_stata(scheme = NULL, ...) scale_color_stata(scheme = NULL, ...)
scheme |
A string, the Stata scheme. One of: |
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color stata:
stata_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_stata(scheme = "s2color")library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_stata(scheme = "s2color")
Categorical (qualitative) color scales used in Tableau.
Use the function scale_colour_gradient_tableau() for the sequential
and scale_colour_gradient2_tableau() for the diverging continuous
color scales from Tableau.
scale_colour_tableau( palette = "Tableau 10", ..., type = "regular", direction = 1 ) scale_fill_tableau( palette = "Tableau 10", ..., type = "regular", direction = 1 ) scale_color_tableau( palette = "Tableau 10", ..., type = "regular", direction = 1 )scale_colour_tableau( palette = "Tableau 10", ..., type = "regular", direction = 1 ) scale_fill_tableau( palette = "Tableau 10", ..., type = "regular", direction = 1 ) scale_color_tableau( palette = "Tableau 10", ..., type = "regular", direction = 1 )
palette |
Palette name. See |
... |
Other arguments passed on to |
type |
The type of palette, one of:
|
direction |
If |
A ggplot2 scale object.
tableau_color_pal() for references.
Other color tableau:
scale_colour_gradient2_tableau(),
scale_colour_gradient_tableau(),
tableau_color_pal(),
tableau_gradient_pal()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + theme_igray() palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["regular"]] for (palette in head(names(palettes), 3L)) { print(p + scale_colour_tableau(palette) + ggtitle(palette)) } # the order of colour can be reversed p + scale_color_tableau(direction = -1)library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + theme_igray() palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["regular"]] for (palette in head(names(palettes), 3L)) { print(p + scale_colour_tableau(palette) + ggtitle(palette)) } # the order of colour can be reversed p + scale_color_tableau(direction = -1)
Color and fill scales which use the palettes in wsj_pal().
These scales should be used with theme_wsj().
scale_colour_wsj(palette = "colors6", ...) scale_color_wsj(palette = "colors6", ...) scale_fill_wsj(palette = "colors6", ...)scale_colour_wsj(palette = "colors6", ...) scale_color_wsj(palette = "colors6", ...) scale_fill_wsj(palette = "colors6", ...)
palette |
A string, the color palette to use. One of
|
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color wsj:
wsj_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_wsj("colors6")library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_wsj("colors6")
Color scales from LibreOffice Calc.
scale_fill_calc(...) scale_colour_calc(...) scale_color_calc(...)scale_fill_calc(...) scale_colour_calc(...) scale_color_calc(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
See theme_calc() for examples.
Other color calc:
calc_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_calc()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_calc()
The classic "ugly" color scales from Excel 97.
scale_fill_excel(...) scale_colour_excel(...) scale_color_excel(...)scale_fill_excel(...) scale_colour_excel(...) scale_color_excel(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color excel:
excel_new_pal(),
excel_pal(),
scale_colour_excel_new()
library("ggplot2") # Line and scatter plot colors p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_excel() + scale_colour_excel() # Bar plot (area/fill) colors ggplot(mpg, aes(x = class, fill = drv)) + geom_bar() + scale_fill_excel() + theme_excel()library("ggplot2") # Line and scatter plot colors p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_excel() + scale_colour_excel() # Bar plot (area/fill) colors ggplot(mpg, aes(x = class, fill = drv)) + geom_bar() + scale_fill_excel() + theme_excel()
Color scales from Google Docs.
scale_fill_gdocs(...) scale_colour_gdocs(...) scale_color_gdocs(...)scale_fill_gdocs(...) scale_colour_gdocs(...) scale_color_gdocs(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
See theme_gdocs() for examples.
Other color gdocs:
gdocs_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_gdocs()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point(size = 3) + scale_colour_gdocs()
Discrete color scales using the chart palettes from Apple Numbers.
scale_fill_numbers(palette = "Classic", ...) scale_colour_numbers(palette = "Classic", ...) scale_color_numbers(palette = "Classic", ...)scale_fill_numbers(palette = "Classic", ...) scale_colour_numbers(palette = "Classic", ...) scale_color_numbers(palette = "Classic", ...)
palette |
Palette name. One of
|
... |
Arguments passed on to
|
A ggplot2 scale object.
See theme_numbers() for examples.
Other color numbers:
numbers_pal()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + theme_numbers() for (palette in head(names(ggthemes_data[["numbers"]]), 3L)) { print(p + scale_colour_numbers(palette) + ggtitle(palette)) }library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + theme_numbers() for (palette in head(names(ggthemes_data[["numbers"]]), 3L)) { print(p + scale_colour_numbers(palette) + ggtitle(palette)) }
See solarized_pal() for details.
scale_fill_solarized(accent = "blue", ...) scale_colour_solarized(accent = "blue", ...) scale_color_solarized(accent = "blue", ...)scale_fill_solarized(accent = "blue", ...) scale_colour_solarized(accent = "blue", ...) scale_color_solarized(accent = "blue", ...)
accent |
A string, the name of the starting color. |
... |
Arguments passed on to
|
A ggplot2 scale object.
Other color solarized:
solarized_pal()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_solarized() + scale_colour_solarized()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_solarized() + scale_colour_solarized()
See stata_linetype_pal() for details.
scale_linetype_stata(...)scale_linetype_stata(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
Other linetype stata:
stata_linetype_pal()
require("ggplot2") if (require("tidyr") && require("dplyr")) { rescale01 <- function(x) { (x - min(x)) / diff(range(x)) } gather(economics, variable, value, -date) |> group_by(variable) |> mutate(value = rescale01(value)) |> ggplot(aes(x = date, y = value, linetype = variable)) + geom_line() + scale_linetype_stata() }require("ggplot2") if (require("tidyr") && require("dplyr")) { rescale01 <- function(x) { (x - min(x)) / diff(range(x)) } gather(economics, variable, value, -date) |> group_by(variable) |> mutate(value = rescale01(value)) |> ggplot(aes(x = date, y = value, linetype = variable)) + geom_line() + scale_linetype_stata() }
See calc_shape_pal() for details.
scale_shape_calc(..., unicode = FALSE)scale_shape_calc(..., unicode = FALSE)
... |
Arguments passed on to
|
unicode |
If |
A ggplot2 scale object.
theme_calc() for examples.
Other shapes calc:
calc_shape_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) + geom_point(size = 3) + scale_shape_calc()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) + geom_point(size = 3) + scale_shape_calc()
This scale has no direct replacement. For circles that vary by amount of
fill, use scale_shape_tableau(palette = "proportions", unicode = TRUE);
see scale_shape_tableau().
scale_shape_circlefill(...)scale_shape_circlefill(...)
... |
Arguments passed on to
|
A ggplot2 scale object.
circlefill_shape_pal() for a description of the palette.
Other shapes:
circlefill_shape_pal(),
cleveland_shape_pal(),
scale_shape_cleveland(),
scale_shape_tremmel(),
tremmel_shape_pal()
# Deprecated. The palette grades circles by how much of each is filled, which # needs Unicode glyphs from the device font, so this example does not draw it. scale_shape_circlefill()# Deprecated. The palette grades circles by how much of each is filled, which # needs Unicode glyphs from the device font, so this example does not draw it. scale_shape_circlefill()
Shape scales from Cleveland "Elements of Graphing Data"
scale_shape_cleveland(overlap = TRUE, ..., unicode = FALSE)scale_shape_cleveland(overlap = TRUE, ..., unicode = FALSE)
overlap |
|
... |
Arguments passed on to
|
unicode |
If |
A ggplot2 scale object.
Cleveland WS. The Elements of Graphing Data. Revised Edition. Hobart Press, Summit, NJ, 1994, pp. 154-164, 234-239.
cleveland_shape_pal() for a description of the palette.
Other shapes:
circlefill_shape_pal(),
cleveland_shape_pal(),
scale_shape_circlefill(),
scale_shape_tremmel(),
tremmel_shape_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) + geom_point(size = 3) + scale_shape_cleveland()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) + geom_point(size = 3) + scale_shape_cleveland()
scale_shape_few() maps discrete variables to up to five easily
discernible shapes. It is based on the shape palette suggested in
Few (2012).
scale_shape_few(...)scale_shape_few(...)
... |
Common |
A ggplot2 scale object.
Few, S. (2012) Show Me the Numbers: Designing Tables and Graphs to Enlighten, Analytics Press, p. 208.
few_shape_pal() for the shape palette that this
scale uses.
Other shapes few:
few_shape_pal()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) + geom_point(size = 3) + scale_shape_few()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) + geom_point(size = 3) + scale_shape_few()
See stata_shape_pal() for details.
scale_shape_stata(..., unicode = FALSE)scale_shape_stata(..., unicode = FALSE)
... |
Arguments passed on to
|
unicode |
If |
A ggplot2 scale object.
Other shapes stata:
stata_shape_pal()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + facet_wrap(~am) p + theme_stata(scheme = "s2color") + scale_shape_stata()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + facet_wrap(~am) p + theme_stata(scheme = "s2color") + scale_shape_stata()
See tableau_shape_pal() for details.
scale_shape_tableau(palette = "default", ..., unicode = FALSE)scale_shape_tableau(palette = "default", ..., unicode = FALSE)
palette |
Palette name. |
... |
Arguments passed on to
|
unicode |
If |
A ggplot2 scale object.
Other shapes tableau:
tableau_shape_pal()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + facet_wrap(~am) p + scale_shape_tableau()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + facet_wrap(~am) p + scale_shape_tableau()
Shape scales from Tremmel (1995)
scale_shape_tremmel(overlap = FALSE, ..., alt = FALSE)scale_shape_tremmel(overlap = FALSE, ..., alt = FALSE)
overlap |
Use an empty circle instead of a solid circle when
|
... |
Arguments passed on to
|
alt |
If |
A ggplot2 scale object.
tremmel_shape_pal() for a description of the palette.
Other shapes:
circlefill_shape_pal(),
cleveland_shape_pal(),
scale_shape_circlefill(),
scale_shape_cleveland(),
tremmel_shape_pal()
library("ggplot2") p <- ggplot(mtcars, aes(x = mpg, y = hp, shape = factor(cyl))) + geom_point() p + scale_shape_tremmel() p + scale_shape_tremmel(alt = TRUE) p + scale_shape_tremmel(overlap = TRUE)library("ggplot2") p <- ggplot(mtcars, aes(x = mpg, y = hp, shape = factor(cyl))) + geom_point() p + scale_shape_tremmel() p + scale_shape_tremmel(alt = TRUE) p + scale_shape_tremmel(overlap = TRUE)
A quick and dirty way to show linetypes.
show_linetypes(linetypes, labels = TRUE)show_linetypes(linetypes, labels = TRUE)
linetypes |
A character vector of linetypes. See
|
labels |
If |
Called for its side effect of creating a plot; returns linetypes
invisibly.
scales::show_col(), show_shapes()
library("scales") show_linetypes(linetype_pal()(3)) show_linetypes(linetype_pal()(3), labels = TRUE)library("scales") show_linetypes(linetype_pal()(3)) show_linetypes(linetype_pal()(3), labels = TRUE)
A quick and dirty way to show shapes.
show_shapes(shapes, labels = TRUE)show_shapes(shapes, labels = TRUE)
shapes |
A numeric or character vector of shapes. See
|
labels |
If |
Called for its side effect of creating a plot; returns shapes
invisibly.
scales::show_col(), show_linetypes()
library("scales") show_shapes(shape_pal()(5)) show_shapes(shape_pal()(3), labels = TRUE)library("scales") show_shapes(shape_pal()(5)) show_shapes(shape_pal()(3), labels = TRUE)
Format numbers with automatic number of digits
smart_digits(x, ...) smart_digits_format(x, ...)smart_digits(x, ...) smart_digits_format(x, ...)
x |
A numeric vector to format. |
... |
Parameters passed to |
A character vector.
smart_digits_format() returns a function with a single argument
x, a numeric vector, that returns a character vector.
Josh O'Brien, Baptiste Auguie, Jeffrey B. Arnold
Josh O'Brien, https://stackoverflow.com/questions/23169938/select-accuracy-to-display-additional-axis-breaks/23171858#23171858.
smart_digits(c(0.1234, 0.5, 1.25)) smart_digits(c(1234.5678, 2000, 10000)) # A labelling function for use in a scale library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + scale_y_continuous(labels = smart_digits_format())smart_digits(c(0.1234, 0.5, 1.25)) smart_digits(c(1234.5678, 2000, 10000)) # A labelling function for use in a scale library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + scale_y_continuous(labels = smart_digits_format())
Qualitative color palette based on Ethan Schoonover's Solarized palette, https://ethanschoonover.com/solarized/. This palette supports up to seven values.
solarized_pal(accent = "blue")solarized_pal(accent = "blue")
accent |
A string, the name of the starting color. |
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
For a given starting color and number of colors in the palette, the other colors are the combination of colors that maximizes the total Euclidean distance between colors in Lab space.
Other color solarized:
scale_fill_solarized()
library("scales") show_col(solarized_pal()(2)) show_col(solarized_pal()(3)) show_col(solarized_pal("red")(4))library("scales") show_col(solarized_pal()(2)) show_col(solarized_pal()(3)) show_col(solarized_pal("red")(4))
The five number summary of a sample is the minimum, first quartile, median, third quartile, and maximum.
stat_fivenumber( mapping = NULL, data = NULL, geom = "boxplot", probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = FALSE, position = "identity", show.legend = NA, inherit.aes = TRUE, ... )stat_fivenumber( mapping = NULL, data = NULL, geom = "boxplot", probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = FALSE, position = "identity", 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 |
geom |
The geometric object to use to display the data for this layer.
When using a
|
probs |
Quantiles to use for the five number summary. |
na.rm |
If |
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
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to
|
A data frame with additional columns:
width: width of the box plot.
min: minimum.
lower: lower hinge, the 25% quantile.
middle: median, the 50% quantile.
upper: upper hinge, the 75% quantile.
max: maximum.
library("ggplot2") ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + stat_fivenumber() # The whiskers can be set to other quantiles ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + stat_fivenumber(probs = c(0.05, 0.25, 0.5, 0.75, 0.95))library("ggplot2") ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + stat_fivenumber() # The whiskers can be set to other quantiles ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + stat_fivenumber(probs = c(0.05, 0.25, 0.5, 0.75, 0.95))
Linetype palette based on the linepattern scheme in Stata. This palette supports up to 15 values.
stata_linetype_pal()stata_linetype_pal()
A palette function. It takes the number of linetypes n and returns a character vector of n
linetype specifications, and can be used as the palette argument of
ggplot2::discrete_scale().
Other linetype stata:
scale_linetype_stata()
stata_linetype_pal()(6) show_linetypes(stata_linetype_pal()(6))stata_linetype_pal()(6) show_linetypes(stata_linetype_pal()(6))
Stata color palettes. See Stata documentation for a description of the schemes, https://www.stata.com/help.cgi?schemes.
stata_pal(scheme = NULL)stata_pal(scheme = NULL)
scheme |
A string, the Stata scheme. One of: |
All these palettes support up to 15 values.
Stata's palettes come in two generations, and both are included here.
Stata 17 and earlier: schemes "s2color", "s1color",
"s1rcolor", and "mono" are built from Stata's classic named
colors (navy, maroon, forest_green, and so on) and the
gs0–gs16 gray scale. "s2color" was Stata's factory
default through Stata 17.
Stata 18 and later: scheme "stcolor" uses the
stc1–stc15 colors introduced in Stata 18. They are brighter
than the classic palette and chosen to stay distinguishable for readers
with a color vision deficiency. The first four are also available under
the aliases stblue, stred, stgreen, and
styellow. "stcolor" has been Stata's factory default since
Stata 18.
"economist" is not one of Stata's general-purpose schemes; it is the
set of Economist-styled colors that Stata ships in
scheme-economist.scheme.
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
Other color stata:
scale_colour_stata()
library("scales") # Stata 18 and later (the current factory default) show_col(stata_pal("stcolor")(15)) # Stata 17 and earlier show_col(stata_pal("s2color")(15)) show_col(stata_pal("s1rcolor")(15)) show_col(stata_pal("s1color")(15)) show_col(stata_pal("mono")(15))library("scales") # Stata 18 and later (the current factory default) show_col(stata_pal("stcolor")(15)) # Stata 17 and earlier show_col(stata_pal("s2color")(15)) show_col(stata_pal("s1rcolor")(15)) show_col(stata_pal("s1color")(15)) show_col(stata_pal("mono")(15))
Shape palette based on the symbol palette in Stata used in scheme s2mono. This palette supports up to 10 values.
stata_shape_pal(unicode = FALSE)stata_shape_pal(unicode = FALSE)
unicode |
If |
A palette function. It takes the number of shapes n and returns an integer vector of n
shape (pch) codes, and can be used as the palette argument of
ggplot2::discrete_scale().
Stata's ten plotting symbols all have a base pch equivalent, so this palette supports ten values on either branch and nothing is dropped: solid and hollow circle, diamond, square and triangle, plus the X and the plus sign.
See scale_shape_stata() for examples.
Other shapes stata:
scale_shape_stata()
stata_shape_pal()(10) show_shapes(stata_shape_pal()(10))stata_shape_pal()(10) show_shapes(stata_shape_pal()(10))
Color palettes used in Tableau.
tableau_color_pal( palette = "Tableau 10", type = c("regular", "ordered-sequential", "ordered-diverging"), direction = 1 ) tableau_colour_pal( palette = "Tableau 10", type = c("regular", "ordered-sequential", "ordered-diverging"), direction = 1 )tableau_color_pal( palette = "Tableau 10", type = c("regular", "ordered-sequential", "ordered-diverging"), direction = 1 ) tableau_colour_pal( palette = "Tableau 10", type = c("regular", "ordered-sequential", "ordered-diverging"), direction = 1 )
palette |
A string, the palette name. See Details for available palettes. |
type |
The type of palette, one of:
|
direction |
If |
Tableau provides three types of color palettes:
"regular" (discrete, qualitative categories),
"ordered-sequential", and "ordered-diverging".
"regular": "Tableau 10", "Tableau 20", "Color Blind", "Seattle Grays", "Traffic", "Miller Stone", "Superfishel Stone", "Nuriel Stone", "Jewel Bright", "Summer", "Winter", "Green-Orange-Teal", "Blue-Red-Brown", "Purple-Pink-Gray", "Hue Circle", "Classic 10", "Classic 10 Medium", "Classic 10 Light", "Classic 20", "Classic Gray 5", "Classic Color Blind", "Classic Traffic Light", "Classic Purple-Gray 6", "Classic Purple-Gray 12", "Classic Green-Orange 6", "Classic Green-Orange 12", "Classic Blue-Red 6", "Classic Blue-Red 12", "Classic Cyclic".
"ordered-diverging": "Orange-Blue Diverging", "Red-Green Diverging", "Green-Blue Diverging", "Red-Blue Diverging", "Red-Black Diverging", "Gold-Purple Diverging", "Red-Green-Gold Diverging", "Sunset-Sunrise Diverging", "Orange-Blue-White Diverging", "Red-Green-White Diverging", "Green-Blue-White Diverging", "Red-Blue-White Diverging", "Red-Black-White Diverging", "Orange-Blue Light Diverging", "Temperature Diverging", "Classic Red-Green", "Classic Red-Blue", "Classic Red-Black", "Classic Area Red-Green", "Classic Orange-Blue", "Classic Green-Blue", "Classic Red-White-Green", "Classic Red-White-Black", "Classic Orange-White-Blue", "Classic Red-White-Black Light", "Classic Orange-White-Blue Light", "Classic Red-White-Green Light", "Classic Red-Green Light".
"ordered-sequential": "Blue-Green Sequential", "Blue Light", "Orange Light", "Blue", "Orange", "Green", "Red", "Purple", "Brown", "Gray", "Gray Warm", "Blue-Teal", "Orange-Gold", "Green-Gold", "Red-Gold", "Classic Green", "Classic Gray", "Classic Blue", "Classic Red", "Classic Orange", "Classic Area Red", "Classic Area Green", "Classic Area Brown".
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
http://vis.stanford.edu/color-names/analyzer/
Maureen Stone, 'Designing Colors for Data' (slides), at the International Symposium on Computational Aesthetics in Graphics, Visualization, and Imaging, Banff, AB, Canada, June 22, 2007.
Heer, Jeffrey and Maureen Stone, 2012 'Color Naming Models for Color Selection, Image Editing and Palette Design', ACM Human Factors in Computing Systems (CHI) http://vis.stanford.edu/files/2012-ColorNameModels-CHI.pdf.
Other color tableau:
scale_colour_gradient2_tableau(),
scale_colour_gradient_tableau(),
scale_colour_tableau(),
tableau_gradient_pal()
library("scales") palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["regular"]] for (palname in names(palettes)) { pal <- tableau_color_pal(palname) max_n <- attr(pal, "max_n") show_col(pal(max_n)) title(main = palname) }library("scales") palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["regular"]] for (palname in names(palettes)) { pal <- tableau_color_pal(palname) max_n <- attr(pal, "max_n") show_col(pal(max_n)) title(main = palname) }
Gradient color palettes using the diverging and sequential continuous color
palettes in Tableau. See tableau_color_pal() for discrete color
palettes.
tableau_gradient_pal(palette = "Blue", type = "ordered-sequential") tableau_seq_gradient_pal(palette = "Blue", ...) tableau_div_gradient_pal(palette = "Orange-Blue Diverging", ...)tableau_gradient_pal(palette = "Blue", type = "ordered-sequential") tableau_seq_gradient_pal(palette = "Blue", ...) tableau_div_gradient_pal(palette = "Orange-Blue Diverging", ...)
palette |
Palette name. For each
|
type |
The type of palette, one of:
|
... |
Arguments passed to |
A palette function. It takes a numeric vector x of values between 0 and 1 and returns a character
vector of hex colors interpolated along the palette, for use as the palette argument of
ggplot2::continuous_scale().
Other color tableau:
scale_colour_gradient2_tableau(),
scale_colour_gradient_tableau(),
scale_colour_tableau(),
tableau_color_pal()
library("scales") x <- seq(0, 1, length = 25) r <- sqrt(outer(x^2, x^2, "+")) palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["ordered-sequential"]] for (palname in names(palettes)) { col <- tableau_seq_gradient_pal(palname)(seq(0, 1, length = 12)) image(r, col = col) title(main = palname) }library("scales") x <- seq(0, 1, length = 25) r <- sqrt(outer(x^2, x^2, "+")) palettes <- ggthemes_data[["tableau"]][["color-palettes"]][["ordered-sequential"]] for (palname in names(palettes)) { col <- tableau_seq_gradient_pal(palname)(seq(0, 1, length = 12)) image(r, col = col) title(main = palname) }
Shape palettes used by Tableau.
tableau_shape_pal( palette = c("default", "filled", "proportions"), unicode = FALSE )tableau_shape_pal( palette = c("default", "filled", "proportions"), unicode = FALSE )
palette |
Palette name. |
unicode |
If |
Not all shape palettes in Tableau are supported, and these palettes are not exact.
Shape palettes in Tableau are used to expose images for use as markers in charts, and thus are sometimes groupings of closely related symbols.
A palette function. It takes the number of shapes n and returns an integer vector of n
shape (pch) codes, and can be used as the palette argument of
ggplot2::discrete_scale().
Supported values by palette: "default" eight (ten with
unicode = TRUE), "filled" six (ten), "proportions"
two (five). Shapes with no base pch equivalent – the sideways triangles,
the solid star, and the partially filled circles – are dropped rather than
approximated by a different shape.
"proportions" encodes fill fraction, which base pch cannot
express at all, so only its empty and full circles survive; they remain
meaningful as a two-value scale. To encode a proportion, map alpha
or fill instead, or use unicode = TRUE with a font covering
Geometric Shapes, such as DejaVu Sans.
Other shapes tableau:
scale_shape_tableau()
# The eight shapes with a font-independent equivalent. show_shapes(tableau_shape_pal()(8)) ## Not run: # All ten, drawn from the device font. Needs a font covering Geometric # Shapes, such as DejaVu Sans. show_shapes(tableau_shape_pal(unicode = TRUE)(10)) ## End(Not run)# The eight shapes with a font-independent equivalent. show_shapes(tableau_shape_pal()(8)) ## Not run: # All ten, drawn from the device font. Needs a font covering Geometric # Shapes, such as DejaVu Sans. show_shapes(tableau_shape_pal(unicode = TRUE)(10)) ## End(Not run)
Theme similar to the default settings of the "base" R graphics.
theme_base(base_size = 16, base_family = "")theme_base(base_size = 16, base_family = "")
base_size |
base font size, given in pts. |
base_family |
base font family |
A ggplot2 theme object (class theme).
Other themes:
theme_clean(),
theme_foundation(),
theme_igray(),
theme_map(),
theme_par(),
theme_solid()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes( x = wt, y = mpg, colour = factor(gear) )) + facet_wrap(~am) p + theme_base() # Change values of par old_par <- par(fg = "blue", bg = "gray", col.lab = "red", font.lab = 3) p + theme_base() par(old_par)library("ggplot2") p <- ggplot(mtcars) + geom_point(aes( x = wt, y = mpg, colour = factor(gear) )) + facet_wrap(~am) p + theme_base() # Change values of par old_par <- par(fg = "blue", bg = "gray", col.lab = "red", font.lab = 3) p + theme_base() par(old_par)
Theme similar to the default settings of LibreOffice Calc charts.
theme_calc(base_size = 10, base_family = "sans")theme_calc(base_size = 10, base_family = "sans")
base_size |
base font size, given in pts. |
base_family |
base font family |
A ggplot2 theme object (class theme).
library("ggplot2") ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + theme_calc() + scale_color_calc() ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + facet_wrap(~am) + theme_calc() + scale_shape_calc()library("ggplot2") ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + theme_calc() + scale_color_calc() ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + facet_wrap(~am) + theme_calc() + scale_shape_calc()
Clean ggplot theme with no panel background, black axis lines and gray fill color for chart elements.
theme_clean(base_size = 12, base_family = "sans")theme_clean(base_size = 12, base_family = "sans")
base_size |
base font size, given in pts. |
base_family |
base font family |
A ggplot2 theme object (class theme).
Konrad Zdeb [email protected]
Other themes:
theme_base(),
theme_foundation(),
theme_igray(),
theme_map(),
theme_par(),
theme_solid()
library("ggplot2") p <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point() + facet_wrap(~am) + geom_smooth(method = "lm", se = FALSE) + theme_clean() plibrary("ggplot2") p <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point() + facet_wrap(~am) + geom_smooth(method = "lm", se = FALSE) + theme_clean() p
A theme that approximates the style of The Economist.
theme_economist( base_size = 10, base_family = "sans", horizontal = TRUE, dkpanel = FALSE ) theme_economist_white( base_size = 11, base_family = "sans", gray_bg = TRUE, horizontal = TRUE )theme_economist( base_size = 10, base_family = "sans", horizontal = TRUE, dkpanel = FALSE ) theme_economist_white( base_size = 11, base_family = "sans", gray_bg = TRUE, horizontal = TRUE )
base_size |
base font size, given in pts. |
base_family |
base font family |
horizontal |
If |
dkpanel |
If |
gray_bg |
If |
theme_economist() implements the standard bluish-gray
background theme in the print The Economist and
economist.com.
theme_economist_white() implements a variant with a white
panel and light gray (or white) background often used by The Economist
blog Graphic Detail.
Use scale_color_economist() with this theme.
The y axis should be displayed on the right hand side.
The Economist uses "ITC Officina Sans" as its font for graphs. If you have access to this font, you can use it with the extrafont package. "Verdana" is a good substitute.
An object of class ggplot2::theme().
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + # Economist puts x-axis labels on the right-hand side scale_y_continuous(position = "right") ## Standard p + theme_economist() + scale_colour_economist() # Change axis lines to vertical p + theme_economist(horizontal = FALSE) + scale_colour_economist() + coord_flip() ## White panel/light gray background p + theme_economist_white() + scale_colour_economist() ## All white variant p + theme_economist_white(gray_bg = FALSE) + scale_colour_economist() ## Not run: ## The Economist uses ITC Officina Sans library("extrafont") p + theme_economist(base_family="ITC Officina Sans") + scale_colour_economist() ## Verdana is a widely available substitute p + theme_economist(base_family="Verdana") + scale_colour_economist() ## End(Not run)library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + # Economist puts x-axis labels on the right-hand side scale_y_continuous(position = "right") ## Standard p + theme_economist() + scale_colour_economist() # Change axis lines to vertical p + theme_economist(horizontal = FALSE) + scale_colour_economist() + coord_flip() ## White panel/light gray background p + theme_economist_white() + scale_colour_economist() ## All white variant p + theme_economist_white(gray_bg = FALSE) + scale_colour_economist() ## Not run: ## The Economist uses ITC Officina Sans library("extrafont") p + theme_economist(base_family="ITC Officina Sans") + scale_colour_economist() ## Verdana is a widely available substitute p + theme_economist(base_family="Verdana") + scale_colour_economist() ## End(Not run)
Theme to replicate the ugly monstrosity that was the old
gray-background Excel chart. Please never use this.
This theme should be combined with the scale_colour_excel()
color scale.
theme_excel(base_size = 12, base_family = "", horizontal = TRUE)theme_excel(base_size = 12, base_family = "", horizontal = TRUE)
base_size |
base font size, given in pts. |
base_family |
base font family |
horizontal |
If |
An object of class ggplot2::theme().
Other themes excel:
theme_excel_new()
library("ggplot2") # Line and scatter plot colors p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_excel() + scale_colour_excel() # Bar plot (area/fill) colors ggplot(mpg, aes(x = class, fill = drv)) + geom_bar() + scale_fill_excel() + theme_excel()library("ggplot2") # Line and scatter plot colors p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_excel() + scale_colour_excel() # Bar plot (area/fill) colors ggplot(mpg, aes(x = class, fill = drv)) + geom_bar() + scale_fill_excel() + theme_excel()
Theme for ggplot2 that is similar to the default style of charts in current versions of Microsoft Excel.
theme_excel_new(base_size = 9, base_family = "sans")theme_excel_new(base_size = 9, base_family = "sans")
base_size |
base font size, given in pts. |
base_family |
base font family |
Excel derives its chart grays from the theme's tx1 color
by luminance transform rather than hardcoding them. Since tx1 is
black in every built-in Office theme, these grays—"#D9D9D9"
gridlines, "#BFBFBF" axis lines, "#595959" text—are the
same whichever theme scale_colour_excel_new() is set to.
Since 2023 the default font in Excel has been Aptos, but base_family
defaults to "sans" because Aptos is rarely installed outside of
Office. Pass base_family = "Aptos Narrow" for a closer match if you
do have it.
An object of class ggplot2::theme().
Other themes excel:
theme_excel()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_excel_new() + scale_colour_excel_new()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_excel_new() + scale_colour_excel_new()
Theme based on the rules and examples from Stephen Few's Show Me the Numbers and "Practical Rules for Using Color in Charts".
theme_few(base_size = 12, base_family = "")theme_few(base_size = 12, base_family = "")
base_size |
base font size, given in pts. |
base_family |
base font family |
A ggplot2 theme object (class theme).
Few, S. (2012) Show Me the Numbers: Designing Tables and Graphs to Enlighten. 2nd edition. Analytics Press.
Stephen Few, "Practical Rules for Using Color in Charts", https://www.perceptualedge.com/articles/visual_business_intelligence/rules_for_using_color.pdf.
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_few() + scale_colour_few() p + theme_few() + scale_colour_few("Light") p + theme_few() + scale_colour_few("Dark") ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + theme_few() + scale_shape_few()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_few() + scale_colour_few() p + theme_few() + scale_colour_few("Light") p + theme_few() + scale_colour_few("Dark") ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, shape = factor(gear))) + theme_few() + scale_shape_few()
Theme inspired by the plots from FiveThirtyEight.com.
theme_fivethirtyeight(base_size = 12, base_family = "sans")theme_fivethirtyeight(base_size = 12, base_family = "sans")
base_size |
base font size, given in pts. |
base_family |
base font family |
A ggplot2 theme object (class theme).
library("ggplot2") p <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point() + facet_wrap(~am) + geom_smooth(method = "lm", se = FALSE) + scale_color_fivethirtyeight() + theme_fivethirtyeight() plibrary("ggplot2") p <- ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) + geom_point() + facet_wrap(~am) + geom_smooth(method = "lm", se = FALSE) + scale_color_fivethirtyeight() + theme_fivethirtyeight() p
This theme is designed to be a foundation from which to build new
themes, and not meant to be used directly. theme_foundation()
is a complete theme with only minimal number of elements defined.
It is easier to create new themes by extending this one rather
than ggplot2::theme_gray() or ggplot2::theme_bw(),
because those themes define elements deep in the hierarchy.
theme_foundation( base_size = 12, base_family = "", ink = "black", paper = "white", accent = "#3366FF" )theme_foundation( base_size = 12, base_family = "", ink = "black", paper = "white", accent = "#3366FF" )
base_size |
base font size, given in pts. |
base_family |
base font family |
ink, paper, accent
|
colour for foreground, background, and accented elements respectively. |
This theme takes ggplot2::theme_gray() and sets all
colour and fill values to NULL, except for the top-level
elements (line, rect, and title), which have
colour = ink, and fill = paper. This leaves the spacing
and non-color defaults of the default ggplot2 themes in place.
Unlike theme_foundation(), the other themes in this package (e.g.
theme_economist(), theme_excel(),
theme_hc()) intentionally replicate a fixed, published
visual style, so they do not expose ink/paper/accent
arguments.
A ggplot2 theme object (class theme).
Other themes:
theme_base(),
theme_clean(),
theme_igray(),
theme_map(),
theme_par(),
theme_solid()
library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme_foundation() # Extend the foundation to build a new theme theme_minimal_box <- function(...) { theme_foundation(...) + theme( panel.grid = element_blank(), axis.ticks = element_line() ) } ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme_minimal_box()library("ggplot2") ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme_foundation() # Extend the foundation to build a new theme theme_minimal_box <- function(...) { theme_foundation(...) + theme( panel.grid = element_blank(), axis.ticks = element_line() ) } ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme_minimal_box()
Theme similar to the default look of charts in Google Docs.
theme_gdocs(base_size = 12, base_family = "sans")theme_gdocs(base_size = 12, base_family = "sans")
base_size |
base font size, given in pts. |
base_family |
base font family |
A ggplot2 theme object (class theme).
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_gdocs() + scale_color_gdocs()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_gdocs() + scale_color_gdocs()
Themes based on Highcharts plots.
theme_hc( base_size = 12, base_family = "sans", style = c("default", "default_dark", "darkunica", "grid_light", "sand_signika"), bgcolor = lifecycle::deprecated() )theme_hc( base_size = 12, base_family = "sans", style = c("default", "default_dark", "darkunica", "grid_light", "sand_signika"), bgcolor = lifecycle::deprecated() )
base_size |
base font size, given in pts. |
base_family |
base font family |
style |
The Highcharts theme to use. One of
|
bgcolor |
Only the Highcharts themes that restyle the chart itself get a style
here. The "high-contrast", "avocado" and "sunset"
themes shipped with Highcharts 13 change nothing but the series colors, so
they are available through hc_pal() alone; combine them with
theme_hc("default") or theme_hc("default_dark").
Highcharts pairs several of these themes with a web font
(darkunica with Unica One, grid_light with Dosis,
sand_signika with Signika). Those are not requested here, since the
font may not be installed; pass base_family to use one.
A ggplot2 theme object (class theme).
https://www.highcharts.com/demo/highcharts/line-chart
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes( x = wt, y = mpg, colour = factor(gear) )) + facet_wrap(~am) p + theme_hc() + scale_colour_hc() p + theme_hc(style = "darkunica") + scale_colour_hc("darkunica") p + theme_hc(style = "grid_light") + scale_colour_hc("grid_light") p + theme_hc(style = "default_dark") + scale_colour_hc("high_contrast_dark") dtemp <- data.frame( months = factor(rep(substr(month.name, 1, 3), 4), levels = substr(month.name, 1, 3)), city = rep(c("Tokyo", "New York", "Berlin", "London"), each = 12), temp = c( 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6, -0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5, -0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0, 3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8 ) ) ggplot(dtemp, aes(x = months, y = temp, group = city, color = city)) + geom_line() + geom_point(size = 1.1) + ggtitle("Monthly Average Temperature") + theme_hc() + scale_colour_hc() ggplot(dtemp, aes(x = months, y = temp, group = city, color = city)) + geom_line() + geom_point(size = 1.1) + ggtitle("Monthly Average Temperature") + theme_hc(style = "darkunica") + scale_colour_hc("darkunica")library("ggplot2") p <- ggplot(mtcars) + geom_point(aes( x = wt, y = mpg, colour = factor(gear) )) + facet_wrap(~am) p + theme_hc() + scale_colour_hc() p + theme_hc(style = "darkunica") + scale_colour_hc("darkunica") p + theme_hc(style = "grid_light") + scale_colour_hc("grid_light") p + theme_hc(style = "default_dark") + scale_colour_hc("high_contrast_dark") dtemp <- data.frame( months = factor(rep(substr(month.name, 1, 3), 4), levels = substr(month.name, 1, 3)), city = rep(c("Tokyo", "New York", "Berlin", "London"), each = 12), temp = c( 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6, -0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5, -0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0, 3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8 ) ) ggplot(dtemp, aes(x = months, y = temp, group = city, color = city)) + geom_line() + geom_point(size = 1.1) + ggtitle("Monthly Average Temperature") + theme_hc() + scale_colour_hc() ggplot(dtemp, aes(x = months, y = temp, group = city, color = city)) + geom_line() + geom_point(size = 1.1) + ggtitle("Monthly Average Temperature") + theme_hc(style = "darkunica") + scale_colour_hc("darkunica")
Theme with white panel and gray background.
theme_igray(base_size = 12, base_family = "")theme_igray(base_size = 12, base_family = "")
base_size |
base font size, given in pts. |
base_family |
base font family |
This theme inverts the colors of ggplot2::theme_gray(), with a
white panel and a light gray area around it. This keeps a white
background for the color scales, like ggplot2::theme_bw(). But
by using a gray background, the plot is closer to the
typographical color of the document, which is the motivation for
using a gray panel in ggplot2::theme_gray(). This is
similar to the style of plots in Stata and Tableau.
A ggplot2 theme object (class theme).
ggplot2::theme_gray(),
ggplot2::theme_bw()
Other themes:
theme_base(),
theme_clean(),
theme_foundation(),
theme_map(),
theme_par(),
theme_solid()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_igray()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_igray()
A clean theme that is good for displaying maps from
ggplot2::geom_map().
theme_map(base_size = 9, base_family = "")theme_map(base_size = 9, base_family = "")
base_size |
base font size, given in pts. |
base_family |
base font family |
A ggplot2 theme object (class theme).
Other themes:
theme_base(),
theme_clean(),
theme_foundation(),
theme_igray(),
theme_par(),
theme_solid()
library("ggplot2") if (requireNamespace("maps", quietly = TRUE) && requireNamespace("mapproj", quietly = TRUE)) { us <- map_data("state") gg <- ggplot(us, aes(x = long, y = lat, group = group)) + geom_polygon(fill = "white", color = "black", linewidth = 0.25) + coord_map("albers", lat0 = 39, lat1 = 45) + theme_map() gg }library("ggplot2") if (requireNamespace("maps", quietly = TRUE) && requireNamespace("mapproj", quietly = TRUE)) { us <- map_data("state") gg <- ggplot(us, aes(x = long, y = lat, group = group)) + geom_polygon(fill = "white", color = "black", linewidth = 0.25) + coord_map("albers", lat0 = 39, lat1 = 45) + theme_map() gg }
Theme similar to the default look of charts in Apple Numbers.
theme_numbers(base_size = 12, base_family = "sans")theme_numbers(base_size = 12, base_family = "sans")
base_size |
base font size, given in pts. |
base_family |
base font family |
The values used here are those in the chart-style-default style of
the theme stylesheet that ships inside Numbers: no chart background fill,
gridlines in the value direction only, a border along the bottom of the
chart but not the other three sides, and no tick marks.
A ggplot2 theme object (class theme).
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_numbers() + scale_color_numbers()library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_numbers() + scale_color_numbers()
The pander package ships with a default theme when the 'unify plots' option is
enabled via panderOptions, which is now also available outside of pander internals, like evals,
eval.msgs or Pandoc.brew.
theme_pander( base_size = 12, base_family = "sans", nomargin = TRUE, ff = NULL, fc = "black", fs = NULL, gM = TRUE, gm = TRUE, gc = "grey", gl = "dashed", boxes = FALSE, bc = "white", pc = "transparent", lp = "right", axis = 1 )theme_pander( base_size = 12, base_family = "sans", nomargin = TRUE, ff = NULL, fc = "black", fs = NULL, gM = TRUE, gm = TRUE, gc = "grey", gl = "dashed", boxes = FALSE, bc = "white", pc = "transparent", lp = "right", axis = 1 )
base_size |
base font size, given in pts. |
base_family |
base font family |
nomargin |
Whether to suppress the white space around the plot. |
ff |
|
fc |
Font color, as a name or hex code. |
fs |
|
gM |
Whether to draw the major grid. |
gm |
Whether to draw the minor grid. |
gc |
Grid color, as a name or hex code. |
gl |
Grid line type ( |
boxes |
Whether to draw a border around the plot. |
bc |
Background color, as a name or hex code. |
pc |
Panel background color, as a name or hex code. |
lp |
Legend position. |
axis |
Axis label angle, as defined by |
A ggplot2 theme object (class theme).
require("ggplot2") if (require("pander")) { p <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point() p + theme_pander() old_grid_color <- panderOptions("graph.grid.color") panderOptions("graph.grid.color", "red") p + theme_pander() panderOptions("graph.grid.color", old_grid_color) p <- ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) + geom_point() p + theme_pander() + scale_color_pander() ggplot(mpg, aes(x = class, fill = drv)) + geom_bar() + scale_fill_pander() + theme_pander() }require("ggplot2") if (require("pander")) { p <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point() p + theme_pander() old_grid_color <- panderOptions("graph.grid.color") panderOptions("graph.grid.color", "red") p + theme_pander() panderOptions("graph.grid.color", old_grid_color) p <- ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) + geom_point() p + theme_pander() + scale_color_pander() ggplot(mpg, aes(x = class, fill = drv)) + geom_bar() + scale_fill_pander() + theme_pander() }
Theme which uses the current "base" graphics parameter values
from graphics::par().
Not all par() parameters are supported, and not all are relevant to
ggplot2 themes.
theme_par(base_size = par()$ps, base_family = par()$family)theme_par(base_size = par()$ps, base_family = par()$family)
base_size |
base font size, given in pts. |
base_family |
base font family |
Currently this theme uses the values of the parameters:
"ps", "family", "fg", "bg", "col", "adj", "font",
"cex.axis", "cex.lab", "cex.main", "cex.sub", "col.axis",
"col.lab", "col.main", "col.sub", "font.axis", "font.lab",
"font.main", "font.sub", "las", "lend", "lheight", "lty",
"mar", "tcl", "tck", "xaxt", "yaxt".
This theme does not translate the base graphics perfectly, so the graphs produced by it will not be identical to those produced by base graphics, most notably in the spacing of the margins.
A ggplot2 theme object (class theme).
Other themes:
theme_base(),
theme_clean(),
theme_foundation(),
theme_igray(),
theme_map(),
theme_solid()
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_par() # theme changes with respect to values of par old_par <- par(font = 2, col.lab = "red", fg = "white", bg = "black") p + theme_par() par(old_par)library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) p + theme_par() # theme changes with respect to values of par old_par <- par(font = 2, col.lab = "red", fg = "white", bg = "black") p + theme_par() par(old_par)
See https://ethanschoonover.com/solarized/ for a description of the Solarized palette.
theme_solarized(base_size = 12, base_family = "", light = TRUE) theme_solarized_2(base_size = 12, base_family = "", light = TRUE)theme_solarized(base_size = 12, base_family = "", light = TRUE) theme_solarized_2(base_size = 12, base_family = "", light = TRUE)
base_size |
base font size, given in pts. |
base_family |
base font family |
light |
If |
Plots made with this theme integrate seamlessly with the Solarized
Beamer color theme.
https://github.com/jrnold/beamercolorthemesolarized.
There are two variations: theme_solarized() is similar
to ggplot2::theme_bw(), while theme_solarized_2() is
similar to ggplot2::theme_gray().
A ggplot2 theme object (class theme).
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) # Light version with different main accent colors for (accent in names(ggthemes::ggthemes_data[["solarized"]][["accents"]])) { print(p + theme_solarized() + scale_colour_solarized(accent)) } # Dark version p + theme_solarized(light = FALSE) + scale_colour_solarized("blue") # Alternative theme p + theme_solarized_2(light = FALSE) + scale_colour_solarized("blue")library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) # Light version with different main accent colors for (accent in names(ggthemes::ggthemes_data[["solarized"]][["accents"]])) { print(p + theme_solarized() + scale_colour_solarized(accent)) } # Dark version p + theme_solarized(light = FALSE) + scale_colour_solarized("blue") # Alternative theme p + theme_solarized_2(light = FALSE) + scale_colour_solarized("blue")
Theme that removes all non-geom elements (lines, text, etc.). Use it when
only the geometric objects are desired. The base_family argument is
ignored; it is kept for consistency with ggplot2::theme_grey().
theme_solid(base_size = 12, base_family = "", fill = NA)theme_solid(base_size = 12, base_family = "", fill = NA)
base_size |
base font size, given in pts. |
base_family |
base font family |
fill |
The background color of the plot. |
A ggplot2 theme object (class theme).
Other themes:
theme_base(),
theme_clean(),
theme_foundation(),
theme_igray(),
theme_map(),
theme_par()
library("ggplot2") ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_solid(fill = "white") ggplot(mtcars, aes(wt, mpg)) + geom_point(color = "white") + theme_solid(fill = "black")library("ggplot2") ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_solid(fill = "white") ggplot(mtcars, aes(wt, mpg)) + geom_point(color = "white") + theme_solid(fill = "black")
Themes based on Stata graph schemes
theme_stata(base_size = 11, base_family = "sans", scheme = NULL)theme_stata(base_size = 11, base_family = "sans", scheme = NULL)
base_size |
base font size, given in pts. |
base_family |
base font family |
scheme |
A string, the Stata scheme. One of: |
These themes approximate Stata schemes using the features ggplot2. The graphical models of Stata and ggplot2 differ in various ways that make an exact replication impossible (or more difficult than it is worth). Some features in Stata schemes not in ggplot2: defaults for specific graph types, different levels of titles, captions and notes. These themes also adopt some of the ggplot2 defaults, and more effort was made to match the colors and sizes of major elements than in matching the margins.
The schemes fall into two generations. "stcolor",
"stcolor_alt", "stmono1", "stmono2" and "stsj"
are the st family introduced in Stata 18, of which "stcolor" is
Stata's current factory default: a white background, a dashed grid on both
axes, horizontal y-axis labels, and a borderless legend beside the plot.
The remaining schemes are the s1/s2 families that were the default through
Stata 17.
Stata expresses text sizes as a percentage of graph height, while ggplot2
uses absolute points, so the two agree only at a particular graph size.
The relative sizes here match Stata exactly; base_size = 12.4
reproduces Stata's absolute sizes at its default 7.5 by 4.5 inch graph.
Two further differences are not expressible in a ggplot2 theme: the number
of legend columns (set by ggplot2::guide_legend() rather than
the theme) and Stata's small default marker size (a geom default).
A ggplot2 theme object (class theme).
https://www.stata.com/help.cgi?schemes
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + labs( title = "Graphs by car type", x = "Weight (lbs.)", y = "MPG" ) # The st family, Stata's default since Stata 18 # stcolor p + theme_stata(scheme = "stcolor") + scale_colour_stata("stcolor") # stcolor_alt, which puts the legend below the plot p + theme_stata(scheme = "stcolor_alt") + scale_colour_stata("stcolor") # stmono1 p + theme_stata(scheme = "stmono1") + scale_colour_stata("mono") # stmono2 p + theme_stata(scheme = "stmono2") + scale_colour_stata("mono") # stsj, the Stata Journal scheme p + theme_stata(scheme = "stsj") + scale_colour_stata("mono") # The s1/s2 families, Stata's defaults through Stata 17 # s2color p + theme_stata(scheme = "s2color") + scale_colour_stata("s2color") # s2mono p + theme_stata(scheme = "s2mono") + scale_colour_stata("mono") # s1color p + theme_stata(scheme = "s1color") + scale_colour_stata("s1color") # s1rcolor p + theme_stata(scheme = "s1rcolor") + scale_colour_stata("s1rcolor") # s1mono p + theme_stata(scheme = "s1mono") + scale_colour_stata("mono")library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + labs( title = "Graphs by car type", x = "Weight (lbs.)", y = "MPG" ) # The st family, Stata's default since Stata 18 # stcolor p + theme_stata(scheme = "stcolor") + scale_colour_stata("stcolor") # stcolor_alt, which puts the legend below the plot p + theme_stata(scheme = "stcolor_alt") + scale_colour_stata("stcolor") # stmono1 p + theme_stata(scheme = "stmono1") + scale_colour_stata("mono") # stmono2 p + theme_stata(scheme = "stmono2") + scale_colour_stata("mono") # stsj, the Stata Journal scheme p + theme_stata(scheme = "stsj") + scale_colour_stata("mono") # The s1/s2 families, Stata's defaults through Stata 17 # s2color p + theme_stata(scheme = "s2color") + scale_colour_stata("s2color") # s2mono p + theme_stata(scheme = "s2mono") + scale_colour_stata("mono") # s1color p + theme_stata(scheme = "s1color") + scale_colour_stata("s1color") # s1rcolor p + theme_stata(scheme = "s1rcolor") + scale_colour_stata("s1rcolor") # s1mono p + theme_stata(scheme = "s1mono") + scale_colour_stata("mono")
Theme based on Chapter 6 'Data-Ink Maximization and Graphical
Design' of Edward Tufte The Visual Display of Quantitative
Information. No border, no axis lines, no grids. This theme works
best in combination with ggplot2::geom_rug() or
geom_rangeframe().
theme_tufte(base_size = 11, base_family = "serif", ticks = TRUE)theme_tufte(base_size = 11, base_family = "serif", ticks = TRUE)
base_size |
base font size, given in pts. |
base_family |
base font family |
ticks |
If |
A ggplot2 theme object (class theme).
The default font family is set to 'serif' as he uses serif fonts for labels in 'The Visual Display of Quantitative Information'. The serif font used by Tufte in his books is a variant of Bembo, while the sans serif font is Gill Sans. If these fonts are installed on your system, then you can use them with the package extrafont.
Tufte, Edward R. (2001) The Visual Display of Quantitative Information, Chapter 6.
Other tufte:
extended_range_breaks_(),
geom_rangeframe(),
geom_tufteboxplot()
library("ggplot2") p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + scale_x_continuous(breaks = extended_range_breaks()(mtcars$wt)) + scale_y_continuous(breaks = extended_range_breaks()(mtcars$mpg)) + ggtitle("Cars") p + geom_rangeframe() + coord_cartesian(clip = "off") + theme_tufte() p + geom_rug() + theme_tufte(ticks = FALSE)library("ggplot2") p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + scale_x_continuous(breaks = extended_range_breaks()(mtcars$wt)) + scale_y_continuous(breaks = extended_range_breaks()(mtcars$mpg)) + ggtitle("Cars") p + geom_rangeframe() + coord_cartesian(clip = "off") + theme_tufte() p + geom_rug() + theme_tufte(ticks = FALSE)
Theme based on the plots in The Wall Street Journal.
theme_wsj( base_size = 12, color = "brown", base_family = "sans", title_family = "mono" )theme_wsj( base_size = 12, color = "brown", base_family = "sans", title_family = "mono" )
base_size |
base font size, given in pts. |
color |
A string, the background color of the plot. One of
|
base_family |
base font family |
title_family |
A string, the font family of the plot title. |
This theme should be used with scale_color_wsj().
A ggplot2 theme object (class theme).
https://pinterest.com/wsjgraphics/wsj-graphics/
library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + ggtitle("Diamond Prices") p + scale_colour_wsj("colors6", "") + theme_wsj() # Use a gray background instead p + scale_colour_wsj("colors6", "") + theme_wsj(color = "gray")library("ggplot2") p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, colour = factor(gear))) + facet_wrap(~am) + ggtitle("Diamond Prices") p + scale_colour_wsj("colors6", "") + theme_wsj() # Use a gray background instead p + scale_colour_wsj("colors6", "") + theme_wsj(color = "gray")
Based on experiments Tremmel (1995) suggests the following shape palettes:
tremmel_shape_pal(overlap = FALSE, alt = FALSE)tremmel_shape_pal(overlap = FALSE, alt = FALSE)
overlap |
Use an empty circle instead of a solid circle when
|
alt |
If |
If two symbols, then use a solid circle and plus sign.
If three symbols, then use a solid circle, empty circle, and an empty triangle. However, that set of symbols does not satisfy the requirement that each symbol should differ from the other symbols in the same feature dimension. A set of three symbols that satisfies this is a circle (curvature), plus sign (number of terminators), triangle (line orientation).
This palette supports up to three values. If more than three groups of data, then separate the groups into different plots.
A palette function. It takes the number of shapes n and returns an integer vector of n
shape (pch) codes, and can be used as the palette argument of
ggplot2::discrete_scale().
Tremmel, Lothar, (1995) "The Visual Separability of Plotting Symbols in Scatterplots" Journal of Computational and Graphical Statistics, https://www.jstor.org/stable/1390760
Other shapes:
circlefill_shape_pal(),
cleveland_shape_pal(),
scale_shape_circlefill(),
scale_shape_cleveland(),
scale_shape_tremmel()
tremmel_shape_pal()(3) # Alternative triple: solid circle, plus sign and empty triangle tremmel_shape_pal(alt = TRUE)(3) show_shapes(tremmel_shape_pal()(3))tremmel_shape_pal()(3) # Alternative triple: solid circle, plus sign and empty triangle tremmel_shape_pal(alt = TRUE)(3) show_shapes(tremmel_shape_pal()(3))
The Wall Street Journal uses many different color palettes in its plots. This collects a few of them, but is by no means exhaustive. Collections of these plots can be found on the WSJ Graphics X (formerly Twitter) feed and Pinterest.
wsj_pal(palette = "colors6")wsj_pal(palette = "colors6")
palette |
A string, the color palette to use. One of
|
A palette function. It takes the number of colors n and returns a character vector of n
hex colors, and can be used as the palette argument of ggplot2::discrete_scale().
The following palettes are defined:
"rgby": red/green/blue/yellow theme.
"red_green": green/red two-color scale for good/bad.
"black_green": black-green 4-color scale for "very negative",
"somewhat negative", "somewhat positive", "very positive".
"dem_rep": Democrat/Republican/Undecided blue/red/gray scale.
"colors6": red, blue, gold, green, orange, and black palette.
Other color wsj:
scale_colour_wsj()
wsj_pal()(6) scales::show_col(wsj_pal("rgby")(4))wsj_pal()(6) scales::show_col(wsj_pal("rgby")(4))