| Version: | 7.0.0 |
| Title: | Extra Themes, Scales and Geoms for 'ggplot2' |
| Depends: | R (≥ 4.1.0) |
| Imports: | cli, ggplot2 (≥ 3.5.2), graphics, grDevices, grid, lifecycle, methods, purrr, rlang, scales (≥ 1.4.0), stats, tibble |
| Suggests: | dplyr, farver, lattice, maps, mapproj, pander, quantreg, spelling, systemfonts, testthat (≥ 3.2.0), tidyr, vdiffr (≥ 1.0.6), withr |
| 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. |
| License: | GPL-2 |
| URL: | https://jrnold.github.io/ggthemes/, https://github.com/jrnold/ggthemes |
| BugReports: | https://github.com/jrnold/ggthemes/issues |
| LazyData: | true |
| Language: | en-US |
| Encoding: | UTF-8 |
| Config/testthat/edition: | 3 |
| Config/Needs/coverage: | covr |
| Config/Needs/data: | stringr |
| Config/Needs/lint: | lintr |
| Config/Needs/readme: | knitr, rmarkdown |
| Config/Needs/website: | pkgdown |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-10-03 18:18:53 UTC; jrnold |
| Author: | Jeffrey B. Arnold [aut, cre, cph] (<https://orcid.org/0000-0001-9953-3904>), Gergely Daroczi [ctb], Bo Werth [ctb], Brian Weitzner [ctb], Joshua Kunst [ctb], Baptiste Auguie [ctb], Bob Rudis [ctb], Hadley Wickham [ctb] (Code from the ggplot2 package.), Justin Talbot [ctb] (Code from the labeling package), Joshua London [ctb] |
| Maintainer: | Jeffrey B. Arnold <jeffrey.arnold@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-03 19:10:02 UTC |
ggthemes: 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.
Author(s)
Maintainer: Jeffrey B. Arnold jeffrey.arnold@gmail.com (<https://orcid.org/0000-0001-9953-3904>)
Authors:
Jeffrey B. Arnold jeffrey.arnold@gmail.com (<https://orcid.org/0000-0001-9953-3904>)
Other contributors:
Gergely Daroczi [contributor]
Bo Werth [contributor]
Brian Weitzner [contributor]
Joshua Kunst [contributor]
Baptiste Auguie [contributor]
Bob Rudis [contributor]
Hadley Wickham (Code from the ggplot2 package.) [contributor]
Justin Talbot (Code from the labeling package) [contributor]
Joshua London [contributor]
See Also
Useful links:
Report bugs at https://github.com/jrnold/ggthemes/issues
Bank a Plot's Own Data to 45 Degrees
Description
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 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 = ...).
Usage
bank_plot(
plot,
method = c("ms", "as", "ao", "was"),
cull = FALSE,
layer = 1,
...
)
Arguments
plot |
A |
method, cull, ... |
Passed to |
layer |
Integer. Which layer of |
Details
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 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.
Value
The plot, with coord_fixed added.
See Also
Examples
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)
Bank a Plot's Own Data at Every Scale
Description
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 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.
Usage
bank_plot_multiscale(
plot,
method = c("ms", "as", "ao", "was"),
cull = TRUE,
layer = 1,
...
)
Arguments
plot |
A |
method, cull, ... |
Passed to |
layer |
Integer. Which layer of |
Details
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.
Value
A named list of ggplot objects, one per retained
scale, in ascending order of frequency and named by frequency index.
References
Heer, Jeffrey and Maneesh Agrawala, 2006. "Multi-Scale Banking to 45." IEEE Transactions On Visualization And Computer Graphics 12(5).
See Also
bank_slopes_multiscale, bank_plot
Examples
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]]
Bank Slopes to 45 degrees
Description
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.
Usage
bank_slopes(
x,
y,
cull = FALSE,
weight = NULL,
method = c("ms", "as", "ao", "was"),
...
)
Arguments
x |
x values |
y |
y values |
cull |
|
weight |
No longer used, but kept for backwards compatibility. |
method |
One of 'ms' (Median Absolute Slope), 'as' (Average Absolute Slope), 'ao' (Average Absolute Orientation), or 'was' (Weighted Average Absolute Orientation). |
... |
No longer used, but kept for backwards compatibility. |
Value
numeric The aspect ratio (x , y).
Methods
As written, all of these methods calculate the aspect ratio (x
/y), but bank_slopes will return (y / x) to be compatible
with link[ggplot2]{coord_fixed()}.
Median Absolute Slopes Banking
Let the aspect ratio be \alpha = \frac{w}{h}
then the median absolute slop banking is the
\alpha such that,
median \left| \frac{s_i}{\alpha} \right| = 1
Let R_z = z_{max} - z_{min} for z = x, y,
and M = median \| s_i \|. Then,
\alpha = M \frac{R_x}{R_y}
Average Absolute Slope Banking
Let the aspect ratio be \alpha = \frac{w}{h}.
then the mean absolute slope banking is the
\alpha such that,
mean \left| \frac{s_i}{\alpha} \right| = 1
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
dy/dx. Let s'_i = s_i R_x / R_y
be the range-normalized slopes. Then \alpha is chosen such
that,
mean \left| \arctan \left( \frac{s'_i}{\alpha} \right) \right| = \frac{\pi}{4}
This has no closed-form solution and is found numerically with
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 \alpha. With s'_i as above and segment run
dx_i, \alpha is chosen such that,
\frac{\sum_i \left|\arctan(s'_i / \alpha)\right|
dx_i \sqrt{1 + (s'_i / \alpha)^2}}
{\sum_i dx_i \sqrt{1 + (s'_i / \alpha)^2}} = \frac{\pi}{4}
This has no closed-form solution and is found numerically with
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.
References
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.
See Also
banking(), bank_plot to bank
a ggplot using its own data, and
bank_slopes_multiscale to bank each frequency scale in the
data separately.
Examples
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)
Multi-Scale Banking to 45 Degrees
Description
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.
Usage
bank_slopes_multiscale(
y,
method = c("ms", "as", "ao", "was"),
cull = TRUE,
window = 3,
sd = 1,
threshold = NULL,
scale_factor = 1.25
)
Arguments
y |
|
method, cull |
Passed to |
window |
|
sd |
|
threshold |
|
scale_factor |
|
Details
The procedure is Algorithm 1 of Heer and Agrawala (2006):
Take the discrete Fourier transform of
yand 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
yto remove all higher frequencies and bank the resulting trend curve to 45 degrees usingbank_slopes.Discard aspect ratios within
scale_factorof 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).
Value
A tibble with one row per retained scale, in
ascending order of frequency, and columns:
frequencyintegerfrequency index, i.e. the number of times the trend repeats across the series.rationumericaspect ratio in they / xsense used bycoord_fixed().aspect_rationumericthe same value as width / height, the convention in which the banking literature reports aspect ratios.
References
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.
See Also
bank_slopes for single-scale banking, and
bank_plot_multiscale to bank a ggplot at every scale.
Examples
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")
Calc color palette (discrete)
Description
Color palettes from LibreOffice Calc. This palette has 12 values.
Usage
calc_pal()
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour calc:
scale_fill_calc()
Examples
library("scales")
show_col(calc_pal()(12))
Calc shape palette (discrete)
Description
Shape palette based on the shapes used in LibreOffice Calc.
Usage
calc_shape_pal(unicode = FALSE)
Arguments
unicode |
If |
Value
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
discrete_scale().
Note
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.
See Also
Other shapes calc:
scale_shape_calc()
Examples
# 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)
Canva.com color palettes
Description
150+ color palettes from canva.com. See canva_palettes().
Usage
canva_pal(palette = "Fresh and bright")
Arguments
palette |
Palette name. See the names of |
Value
A function that takes a single value, the number of colors to use.
Examples
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 Color Palettes from Canva
Description
150 four-color palettes by the canva.com design school. These palettes were derived from photos and "impactful websites".
Usage
canva_palettes
Format
A named list of character vector.
The names are the palette names. The values of the character vectors
are hex colors, e.g. "#f98866".
References
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.
Examples
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))
}
Filled Circle Shape palette (discrete)
Description
'r lifecycle::badge("deprecated")'
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.
Usage
circlefill_shape_pal()
Value
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
discrete_scale().
References
Lewandowsky, Stephan and Ian Spence (1989) "Discriminating Strata in Scatterplots", Journal of the American Statistical Association, https://www.jstor.org/stable/2289649
See Also
Other shapes:
cleveland_shape_pal(),
scale_shape_circlefill(),
scale_shape_cleveland(),
scale_shape_tremmel(),
tremmel_shape_pal()
Examples
circlefill_shape_pal()(3)
Shape palette from Cleveland "Elements of Graphing Data" (discrete).
Description
Shape palettes for overlapping and non-overlapping points.
Usage
cleveland_shape_pal(overlap = TRUE, unicode = FALSE)
Arguments
overlap |
|
unicode |
If |
Value
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
discrete_scale().
Note
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.
References
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
See Also
Other shapes:
circlefill_shape_pal(),
scale_shape_circlefill(),
scale_shape_cleveland(),
scale_shape_tremmel(),
tremmel_shape_pal()
Examples
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)
Colorblind Color Palette (Discrete) and Scales
Description
An eight-color colorblind safe qualitative discrete palette.
'r lifecycle::badge("deprecated")'
Usage
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_colorblind(black = TRUE, ...)
scale_fill_colourblind(black = TRUE, ...)
Arguments
black |
If |
... |
Arguments passed on to
|
Value
colorblind_pal() and colourblind_pal() return a palette function that takes the number of
colours n and returns a character vector of n hex colours. The scale_*() functions
return a ggplot2 scale object.
References
Chang, W. "Cookbook for R"
https://jfly.iam.u-tokyo.ac.jp/color
See Also
The dichromat package, dichromat_pal(),
and scale_color_tableau() for other colorblind palettes.
Examples
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()
Economist color palette (discrete)
Description
The nine colors The Economist uses for chart series: blue, cyan, green, yellow, olive, purple, gold, gray, and red, in that order. Red comes last because the house style reserves it for data the chart is making a point about, rather than handing it out as an ordinary series color.
Usage
economist_pal(fill = deprecated())
Arguments
fill |
'r lifecycle::badge("deprecated")' No longer has any effect. |
Details
A tenth color, "Econ red", is the brighter masthead red used for the
tag rectangle and for single-series highlights. It is excluded from
this palette; take it from
ggthemes_data$economist$main when you need it.
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour economist:
economist_seq_pal(),
scale_colour_economist(),
scale_colour_economist_c()
Examples
library("scales")
show_col(economist_pal()(6))
## the full set of nine series colours
show_col(economist_pal()(9))
Economist sequential color palettes
Description
The Economist's "equal lightness colour scales": six ordered steps for each of the nine hues in the main chart palette, running darkest to lightest. Use them for ordered data, where the main palette is for unordered categories.
Usage
economist_seq_pal(hue = "blue")
economist_gradient_pal(hue = "blue")
Arguments
hue |
|
Details
economist_seq_pal() returns the six steps themselves, for
discrete ordered data. economist_gradient_pal() interpolates
between them, for continuous data.
Value
economist_seq_pal() returns a palette function that takes the number of colours n and
returns the first n of the six hex colours for hue, for use with
discrete_scale(). economist_gradient_pal() returns a palette function that
takes a numeric vector x of values between 0 and 1 and returns hex colours interpolated between
those steps, for use with continuous_scale().
See Also
Other colour economist:
economist_pal(),
scale_colour_economist(),
scale_colour_economist_c()
Examples
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)))
Excel (current versions) color palettes (discrete)
Description
Color palettes used by current versions of Microsoft Office and Excel.
Usage
excel_new_pal(theme = "Office")
Arguments
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:
|
Details
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.
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour excel:
excel_pal(),
scale_colour_excel_new(),
scale_fill_excel()
Examples
library("scales")
for (i in names(ggthemes::ggthemes_data$excel$themes)) {
show_col(excel_new_pal(theme = i)(6))
}
Excel 97 ugly color palettes (discrete)
Description
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.
Usage
excel_pal(line = TRUE)
Arguments
line |
If |
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour excel:
excel_new_pal(),
scale_colour_excel_new(),
scale_fill_excel()
Examples
library("scales")
show_col(excel_pal()(7))
show_col(excel_pal(line = FALSE)(7))
Pretty axis breaks inclusive of extreme values
Description
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.
Usage
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, ...)
Arguments
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 |
Details
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)).
Value
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.
Author(s)
Justin Talbot jtalbot@stanford.edu, Jeffrey B. Arnold, Baptiste Auguie
References
Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes, InfoVis 2010.
See Also
Other tufte:
geom_rangeframe(),
geom_tufteboxplot(),
theme_tufte()
Examples
# 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()
Color Palettes Few "Show Me the Numbers"
Description
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.
Usage
few_pal(palette = "Medium")
Arguments
palette |
One of |
Details
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.
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
References
Few, S. (2012) Show Me the Numbers: Designing Tables and Graphs to Enlighten. 2nd edition. Analytics Press.
"Practical Rules for Using Color in Charts".
See Also
Other colour few:
scale_colour_few()
Examples
library("scales")
show_col(few_pal()(7))
show_col(few_pal("Dark")(7))
show_col(few_pal("Light")(7))
Shape palette from "Show Me the Numbers" (discrete)
Description
Shape palette from Stephen Few's, "Show Me the Numbers". The shape palette consists of five shapes: circle, square, triangle, plus, times.
Usage
few_shape_pal()
Value
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
discrete_scale().
References
Few, S. (2012) Show Me the Numbers: Designing Tables and Graphs to Enlighten, Analytics Press, p. 208.
Examples
few_shape_pal()(5)
show_shapes(few_shape_pal()(5))
FiveThirtyEight color palette
Description
The standard three-color FiveThirtyEight palette for line plots comprises blue, red, and green.
Usage
fivethirtyeight_pal()
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour fivethirtyeight:
scale_colour_fivethirtyeight()
Examples
library("scales")
show_col(fivethirtyeight_pal()(3))
Google Docs color palette (discrete)
Description
Color palettes from Google Docs. This palette includes 20 colors.
Usage
gdocs_pal()
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour gdocs:
scale_fill_gdocs()
Examples
library("scales")
show_col(gdocs_pal()(24))
Range Frames
Description
Axis lines which extend to the maximum and minimum of the plotted data.
Usage
geom_rangeframe(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
sides = "bl",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
Arguments
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 |
Details
This should be used with 'coord_cartesian(clip="off")' in order to correctly draw the lines.
Secondary axes (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.
Value
A ggplot2 layer.
Aesthetics
colour
size
linetype
alpha
References
Tufte, Edward R. (2001) The Visual Display of Quantitative Information, Chapter 6.
See Also
Other geom tufte:
geom_tufteboxplot()
Other tufte:
extended_range_breaks_(),
geom_tufteboxplot(),
theme_tufte()
Examples
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()
Tufte's Box Plot
Description
Edward Tufte's revisions of the box plot as described in The Visual Display of Quantitative Information. This functions 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.
Usage
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",
...
)
Arguments
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 |
colour for outlying points |
outlier.shape |
shape of outlying points |
outlier.size |
size of outlying points |
outlier.stroke |
stroke for 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 |
If |
whisker.type |
If |
... |
Other arguments passed on to
|
Value
A ggplot2 layer.
Aesthetics
x [required]
y [required]
colour
size
linewidth
linetype
shape
fill
alpha
References
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.
See Also
Other geom tufte:
geom_rangeframe()
Other tufte:
extended_range_breaks_(),
geom_rangeframe(),
theme_tufte()
Examples
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)
Palette and theme data
Description
The ggthemes environment contains various values used in
themes and palettes. This is undocumented and subject to change.
Usage
ggthemes_data
Format
A list object.
Details
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().
Highcharts color palette (discrete)
Description
Highcharts uses many different color palettes in its plots. This collects the palettes shipped with Highcharts 13, plus the default Highcharts used before v11.
Usage
hc_pal(palette = "default")
Arguments
palette |
|
Details
"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.
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour hc:
scale_colour_hc()
Examples
hc_pal()(6)
scales::show_col(hc_pal("darkunica")(4))
Apple Numbers color palettes (discrete)
Description
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.
Usage
numbers_pal(palette = "Classic")
Arguments
palette |
Palette name. One of
|
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour numbers:
scale_fill_numbers()
Examples
library("scales")
show_col(numbers_pal()(6))
show_col(numbers_pal("Spectrum")(6))
Color palette from the pander package
Description
The pander ships with a default colorblind and printer-friendly
color palette borrowed from https://jfly.iam.u-tokyo.ac.jp/color/.
Usage
palette_pander(n, random_order = FALSE)
Arguments
n |
number of colors. This palette supports up to eight colors. |
random_order |
if the palette should be reordered randomly before rendering each plot to get colorful images |
Value
A character vector of n hex colours, recycled if n exceeds the number of colours available.
Unlike the other *_pal() functions, this is itself the palette function.
See Also
Other colour pander:
scale_color_pander()
Examples
palette_pander(8)
# the same colors in a random order
palette_pander(8, random_order = TRUE)
Color Palettes from Paul Tol's "Colour Schemes"
Description
ptol_pal() was deprecated in ggthemes 7.0.0. Use the
khroma package instead, which
tracks Paul Tol's colour schemes as he revises them.
This palette is the 12-colour 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".
Usage
ptol_pal()
Details
Incorporation of the palette into an R package was originally inspired by Peter Carl's Paul Tol 21 Gun Salute
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
References
Paul Tol. 2012. "Colour Schemes." SRON Technical Note, SRON/EPS/TN/09-002. https://sronpersonalpages.nl/~pault/data/colourschemes.pdf
See Also
Other colour ptol:
scale_colour_ptol()
Examples
library("scales")
show_col(ptol_pal()(6))
show_col(ptol_pal()(4))
show_col(ptol_pal()(12))
Color scale from the pander package
Description
The pander ships with a default colorblind and printer-friendly color
palette borrowed from https://jfly.iam.u-tokyo.ac.jp/color/.
Usage
scale_color_pander(...)
scale_colour_pander(...)
scale_fill_pander(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other colour pander:
palette_pander()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_pander()
Discrete color scale using canva.com color palettes
Description
Color scale for canva.com color palettes described in
canva_palettes().
Usage
scale_colour_canva(..., palette = "Fresh and bright")
scale_color_canva(..., palette = "Fresh and bright")
scale_fill_canva(..., palette = "Fresh and bright")
Arguments
... |
Arguments passed to |
palette |
Palette name. See the names of |
Value
A ggplot2 scale object.
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_canva()
Economist color scales
Description
Color scales using the colors in the Economist graphics.
Usage
scale_colour_economist(...)
scale_color_economist(...)
scale_fill_economist(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
theme_economist() for examples.
Other colour economist:
economist_pal(),
economist_seq_pal(),
scale_colour_economist_c()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_economist()
Economist sequential color scales
Description
Color scales built from The Economist's equal-lightness color scales.
The _c scales are continuous; the _ordinal scales are
discrete, for ordered factors. See scale_colour_economist()
for the unordered categorical scales.
Usage
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", ...)
Arguments
hue |
|
guide |
Type of legend. Use |
... |
Other arguments passed on to the underlying scale. |
Value
A ggplot2 scale object.
See Also
Other colour economist:
economist_pal(),
economist_seq_pal(),
scale_colour_economist()
Examples
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")
Excel (current versions) color scales
Description
Discrete color scales used in current versions of Microsoft Office and Excel.
Usage
scale_colour_excel_new(theme = "Office", ...)
scale_color_excel_new(theme = "Office", ...)
scale_fill_excel_new(theme = "Office", ...)
Arguments
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
|
Value
A ggplot2 scale object.
See Also
Other colour excel:
excel_new_pal(),
excel_pal(),
scale_fill_excel()
Examples
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()
Color scales from Few's "Practical Rules for Using Color in Charts"
Description
See few_pal().
Usage
scale_colour_few(palette = "Medium", ...)
scale_color_few(palette = "Medium", ...)
scale_fill_few(palette = "Light", ...)
Arguments
palette |
One of |
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other colour few:
few_pal()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_few("Dark")
FiveThirtyEight color scales
Description
Color scales using the colors in the FiveThirtyEight graphics.
Usage
scale_colour_fivethirtyeight(...)
scale_color_fivethirtyeight(...)
scale_fill_fivethirtyeight(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
theme_fivethirtyeight() for examples.
Other colour fivethirtyeight:
fivethirtyeight_pal()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_fivethirtyeight()
Tableau diverging colour scales (continuous)
Description
Continuous color scales using the diverging color scales in Tableau.
See scale_colour_tableau() for Tabaleau discrete color scales,
and scale_colour_gradient_tableau() for sequential color scales.
Usage
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"
)
Arguments
palette |
Palette name.
|
... |
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 |
Value
A ggplot2 scale object.
See Also
Other colour tableau:
scale_colour_gradient_tableau(),
scale_colour_tableau(),
tableau_color_pal(),
tableau_gradient_pal()
Examples
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")
Tableau sequential colour scales (continuous)
Description
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.
Usage
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_fill_continuous_tableau(
palette = "Blue",
...,
na.value = "grey50",
guide = "colourbar"
)
Arguments
palette |
Palette name.
|
... |
Arguments passed to |
na.value |
Colour to use for missing values |
guide |
Type of legend. Use |
Value
A ggplot2 scale object.
See Also
Other colour tableau:
scale_colour_gradient2_tableau(),
scale_colour_tableau(),
tableau_color_pal(),
tableau_gradient_pal()
Examples
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))
}
Highcharts color and fill scales
Description
Colour and fill scales which use the palettes in
hc_pal() and are meant for use with
theme_hc().
Usage
scale_colour_hc(palette = "default", ...)
scale_color_hc(palette = "default", ...)
scale_fill_hc(palette = "default", ...)
Arguments
palette |
|
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other colour hc:
hc_pal()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_hc(palette = "darkunica")
Color Scales from Paul Tol's "Colour Schemes
Description
These scales were deprecated in ggthemes 7.0.0. Use the khroma package instead, which tracks Paul Tol's colour schemes as he revises them.
They draw the 12-colour 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.
Usage
scale_colour_ptol(...)
scale_color_ptol(...)
scale_fill_ptol(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other colour ptol:
ptol_pal()
Examples
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()
Stata color scales
Description
See stata_pal() for details.
Usage
scale_colour_stata(scheme = NULL, ...)
scale_fill_stata(scheme = NULL, ...)
scale_color_stata(scheme = NULL, ...)
Arguments
scheme |
|
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other colour stata:
stata_pal()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_stata(scheme = "s2color")
Tableau color scales (discrete)
Description
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.
Usage
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,
...
)
Arguments
palette |
Palette name. See |
type |
Palette type. One of |
direction |
If 1, the default, then use the original order of colors. If -1, then reverse the order. |
... |
Other arguments passed on to |
Value
A ggplot2 scale object.
See Also
tableau_color_pal() for references.
Other colour tableau:
scale_colour_gradient2_tableau(),
scale_colour_gradient_tableau(),
tableau_color_pal(),
tableau_gradient_pal()
Examples
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)
Wall Street Journal color and fill scales
Description
Colour and fill scales which use the palettes in wsj_pal().
These scales should be used with theme_wsj().
Usage
scale_colour_wsj(palette = "colors6", ...)
scale_color_wsj(palette = "colors6", ...)
scale_fill_wsj(palette = "colors6", ...)
Arguments
palette |
|
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other colour wsj:
wsj_pal()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_wsj("colors6")
LibreOffice Calc color scales
Description
Color scales from LibreOffice Calc.
Usage
scale_fill_calc(...)
scale_colour_calc(...)
scale_color_calc(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
See theme_calc() for examples.
Other colour calc:
calc_pal()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_calc()
Excel 97 ugly color scales
Description
The classic "ugly" color scales from Excel 97.
Usage
scale_fill_excel(...)
scale_colour_excel(...)
scale_color_excel(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other colour excel:
excel_new_pal(),
excel_pal(),
scale_colour_excel_new()
Examples
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()
Google Docs color scales
Description
Color scales from Google Docs.
Usage
scale_fill_gdocs(...)
scale_colour_gdocs(...)
scale_color_gdocs(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
See theme_gdocs() for examples.
Other colour gdocs:
gdocs_pal()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(gear))) +
geom_point(size = 3) +
scale_colour_gdocs()
Apple Numbers color scales
Description
Discrete color scales using the chart palettes from Apple Numbers.
Usage
scale_fill_numbers(palette = "Classic", ...)
scale_colour_numbers(palette = "Classic", ...)
scale_color_numbers(palette = "Classic", ...)
Arguments
palette |
Palette name. One of
|
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
See theme_numbers() for examples.
Other colour numbers:
numbers_pal()
Examples
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))
}
Solarized color scales
Description
See solarized_pal() for details.
Usage
scale_fill_solarized(accent = "blue", ...)
scale_colour_solarized(accent = "blue", ...)
scale_color_solarized(accent = "blue", ...)
Arguments
accent |
|
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other colour solarized:
solarized_pal()
Examples
library("ggplot2")
p <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
facet_wrap(~am)
p + theme_solarized() + scale_colour_solarized()
Stata linetype palette (discrete)
Description
See stata_linetype_pal() for details.
Usage
scale_linetype_stata(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
Other linetype stata:
stata_linetype_pal()
Examples
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()
}
Calc shape scale
Description
See calc_shape_pal() for details.
Usage
scale_shape_calc(..., unicode = FALSE)
Arguments
... |
Arguments passed on to
|
unicode |
If |
Value
A ggplot2 scale object.
See Also
theme_calc() for examples.
Other shapes calc:
calc_shape_pal()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) +
geom_point(size = 3) +
scale_shape_calc()
Filled Circle Shape palette (discrete)
Description
'r lifecycle::badge("deprecated")'
Usage
scale_shape_circlefill(...)
Arguments
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
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()
Examples
# 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"
Description
Shape scales from Cleveland "Elements of Graphing Data"
Usage
scale_shape_cleveland(overlap = TRUE, ..., unicode = FALSE)
Arguments
overlap |
|
... |
Arguments passed on to
|
unicode |
If |
Value
A ggplot2 scale object.
References
Cleveland WS. The Elements of Graphing Data. Revised Edition. Hobart Press, Summit, NJ, 1994, pp. 154-164, 234-239.
See Also
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()
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) +
geom_point(size = 3) +
scale_shape_cleveland()
Scales for shapes from "Show Me the Numbers"
Description
scale_shape_few() maps discrete variables to up to five easily
discernible shapes. It is based on the shape palette suggested in
Few (2012).
Usage
scale_shape_few(...)
Arguments
... |
Common |
Value
A ggplot2 scale object.
References
Few, S. (2012) Show Me the Numbers: Designing Tables and Graphs to Enlighten, Analytics Press, p. 208.
See Also
scale_shape_few() for the shape palette that this
scale uses.
Examples
library("ggplot2")
ggplot(mtcars, aes(x = wt, y = mpg, shape = factor(gear))) +
geom_point(size = 3) +
scale_shape_few()
Stata shape scale
Description
See stata_shape_pal() for details.
Usage
scale_shape_stata(..., unicode = FALSE)
Arguments
... |
Arguments passed on to
|
unicode |
If |
Value
A ggplot2 scale object.
See Also
Other shapes stata:
stata_shape_pal()
Examples
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()
Tableau shape scales
Description
See tableau_shape_pal() for details.
Usage
scale_shape_tableau(palette = "default", ..., unicode = FALSE)
Arguments
palette |
Palette name. |
... |
Arguments passed on to
|
unicode |
If |
Value
A ggplot2 scale object.
See Also
Other shapes tableau:
tableau_shape_pal()
Examples
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)
Description
Shape scales from Tremmel (1995)
Usage
scale_shape_tremmel(overlap = FALSE, alt = FALSE, ...)
Arguments
overlap |
use an empty circle instead of a solid circle when
|
alt |
If |
... |
Arguments passed on to
|
Value
A ggplot2 scale object.
See Also
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()
Examples
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)
Show linetypes
Description
A quick and dirty way to show linetypes.
Usage
show_linetypes(linetypes, labels = TRUE)
Arguments
linetypes |
A character vector of linetypes. See
|
labels |
Label each line with its linetype (lty) value. |
Value
This function called for the side effect of creating a plot.
It returns linetypes.
See Also
show_col(), show_linetypes()
Examples
library("scales")
show_linetypes(linetype_pal()(3))
show_linetypes(linetype_pal()(3), labels = TRUE)
Show shapes
Description
A quick and dirty way to show shapes.
Usage
show_shapes(shapes, labels = TRUE)
Arguments
shapes |
A numeric or character vector of shapes. See
|
labels |
Include the plotting character value of the symbol. |
Value
This function called for the side effect of creating a plot.
It returns shapes.
See Also
show_col(), show_linetypes()
Examples
library("scales")
show_shapes(shape_pal()(5))
show_shapes(shape_pal()(3), labels = TRUE)
Format numbers with automatic number of digits
Description
Format numbers with automatic number of digits
Usage
smart_digits(x, ...)
smart_digits_format(x, ...)
Arguments
x |
A numeric vector to format |
... |
Parameters passed to |
Value
A character vector.
smart_digits_format() returns a function with a single argument
x, a numeric vector, that returns a character vector.
Author(s)
Josh O'Brien, Baptiste Auguie, Jeffrey B. Arnold
References
Josh O'Brien, https://stackoverflow.com/questions/23169938/select-accuracy-to-display-additional-axis-breaks/23171858#23171858.
Examples
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())
Solarized color palette (discrete)
Description
Qualitative color palate based on the Ethan Schoonover's Solarized palette, https://ethanschoonover.com/solarized/. This palette supports up to seven values.
Usage
solarized_pal(accent = "blue")
Arguments
accent |
|
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
Note
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 L*a*b space.
See Also
Other colour solarized:
scale_fill_solarized()
Examples
library("scales")
show_col(solarized_pal()(2))
show_col(solarized_pal()(3))
show_col(solarized_pal("red")(4))
Base colors for Solarized light and dark themes
Description
Base colors for Solarized light and dark themes
Usage
solarized_rebase(light = TRUE)
Arguments
light |
Creates the base colors for a light or dark solarized theme. See https://ethanschoonover.com/solarized/. This function is a port of the CSS style example. |
Value
A named character vector of eight hex colours, named rebase03 to rebase3.
Calculate components of a five-number summary
Description
The five number summary of a sample is the minimum, first quartile, median, third quartile, and maximum.
Usage
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,
...
)
Arguments
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
|
Value
A data frame with additional columns:
width |
width of boxplot |
min |
minimum |
lower |
lower hinge, 25% quantile |
middle |
median, 50% quantile |
upper |
upper hinge, 75% quantile |
max |
maximum |
See Also
Examples
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))
Stata linetype palette (discrete)
Description
Linetype palette based on the linepattern scheme in Stata. This palette supports up to 15 values.
Usage
stata_linetype_pal()
Value
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
discrete_scale().
See Also
Other linetype stata:
scale_linetype_stata()
Examples
stata_linetype_pal()(6)
show_linetypes(stata_linetype_pal()(6))
Stata color palettes (discrete)
Description
Stata color palettes. See Stata documentation for a description of the schemes, https://www.stata.com/help.cgi?schemes.
Usage
stata_pal(scheme = NULL)
Arguments
scheme |
|
Details
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 thegs0–gs16gray scale."s2color"was Stata's factory default through Stata 17.- Stata 18 and later
Scheme
"stcolor"uses thestc1–stc15colors 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 aliasesstblue,stred,stgreen, andstyellow."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.
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
See Also
Other colour stata:
scale_colour_stata()
Examples
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))
Stata shape palette (discrete)
Description
Shape palette based on the symbol palette in Stata used in scheme s2mono. This palette supports up to 10 values.
Usage
stata_shape_pal(unicode = FALSE)
Arguments
unicode |
If |
Value
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
discrete_scale().
Note
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 Also
See scale_shape_stata() for examples.
Other shapes stata:
scale_shape_stata()
Examples
stata_shape_pal()(10)
show_shapes(stata_shape_pal()(10))
Tableau Color Palettes (discrete)
Description
Color palettes used in Tableau.
Usage
tableau_color_pal(
palette = "Tableau 10",
type = c("regular", "ordered-sequential", "ordered-diverging"),
direction = 1
)
Arguments
palette |
Palette name. See Details for available palettes. |
type |
Type of palette. One of |
direction |
If 1, the default, then use the original order of colors. If -1, then reverse the order. |
Details
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"
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
References
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.
See Also
Other colour tableau:
scale_colour_gradient2_tableau(),
scale_colour_gradient_tableau(),
scale_colour_tableau(),
tableau_gradient_pal()
Examples
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)
}
Tableau colour gradient palettes (continuous)
Description
Gradient color palettes using the diverging and sequential continous color
palettes in Tableau. See tableau_color_pal() for discrete color
palettes.
Usage
tableau_gradient_pal(palette = "Blue", type = "ordered-sequential")
tableau_seq_gradient_pal(palette = "Blue", ...)
tableau_div_gradient_pal(palette = "Orange-Blue Diverging", ...)
Arguments
palette |
Palette name.
|
type |
Palette type, either |
... |
Arguments passed to |
Value
A palette function. It takes a numeric vector x of values between 0 and 1 and returns a character
vector of hex colours interpolated along the palette, for use as the palette argument of
continuous_scale().
See Also
Other colour tableau:
scale_colour_gradient2_tableau(),
scale_colour_gradient_tableau(),
scale_colour_tableau(),
tableau_color_pal()
Examples
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)
}
Tableau Shape Palettes (discrete)
Description
Shape palettes used by Tableau.
Usage
tableau_shape_pal(
palette = c("default", "filled", "proportions"),
unicode = FALSE
)
Arguments
palette |
Palette name. |
unicode |
If |
Details
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.
Value
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
discrete_scale().
Note
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.
See Also
Other shapes tableau:
scale_shape_tableau()
Examples
# 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 Base
Description
Theme similar to the default settings of the ‘base’ R graphics.
Usage
theme_base(base_size = 16, base_family = "")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Value
A ggplot2 theme object (class theme).
See Also
Other themes:
theme_clean(),
theme_foundation(),
theme_igray(),
theme_par(),
theme_solid()
Examples
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 Calc
Description
Theme similar to the default settings of LibreOffice Calc charts.
Usage
theme_calc(base_size = 10, base_family = "sans")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Value
A ggplot2 theme object (class theme).
Examples
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
Description
Clean ggplot theme with no panel background, black axis lines and grey fill colour for chart elements.
Usage
theme_clean(base_size = 12, base_family = "sans")
Arguments
base_size |
Base font size. |
base_family |
Base font family. |
Value
A ggplot2 theme object (class theme).
Author(s)
Konrad Zdeb name.surname@me.com
See Also
Other themes:
theme_base(),
theme_foundation(),
theme_igray(),
theme_par(),
theme_solid()
Examples
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()
p
ggplot color theme based on the Economist
Description
A theme that approximates the style of charts in The Economist.
Usage
theme_economist(
base_size = 10,
base_family = "sans",
horizontal = TRUE,
dkpanel = deprecated()
)
theme_economist_white(
base_size = 10,
base_family = "sans",
gray_bg = deprecated(),
horizontal = TRUE
)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
horizontal |
|
dkpanel |
'r lifecycle::badge("deprecated")' The darker panel was a feature of the pre-2017 design and no longer has any effect. |
gray_bg |
'r lifecycle::badge("deprecated")' No longer has any effect. |
Details
This follows the chart design The Economist introduced in 2017
and still publishes today: a white plot area on a pale ground, light
horizontal gridlines only, a black x-axis baseline with tick marks
below it, and no y-axis rule or ticks. Use
scale_colour_economist() with it.
Two conventions of the house style cannot be expressed as theme elements, and have to be set on the plot itself:
-
The Economist puts the y axis on the right. Use
scale_y_continuous(position = "right"). Charts are tagged with a small red rectangle above the title. Draw it with
annotate()orgrid.rect()in "Econ red", which isggthemes_data$economist$mainrow"econ red".
The Economist sets charts in "Econ Sans", which is not publicly available. Any narrow humanist sans is a reasonable substitute; with the extrafont package, "Roboto Condensed" or "Fira Sans Condensed" are close.
Value
An object of class theme().
References
-
The Economist visual styleguide, version 1.2, 4 May 2017.
Examples
library("ggplot2")
p <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
facet_wrap(~am) +
# The Economist puts the y-axis labels on the right-hand side
scale_y_continuous(position = "right") +
labs(
title = "Heavier, thirstier",
subtitle = "Fuel economy v weight, by number of forward gears",
caption = "Source: Motor Trend, 1974"
)
## Standard
p + theme_economist() +
scale_colour_economist()
# Vertical gridlines, for use with coord_flip()
p + theme_economist(horizontal = FALSE) +
scale_colour_economist() +
coord_flip()
## Ordered data uses one hue's equal-lightness steps instead
ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, colour = hp)) +
scale_colour_economist_c(hue = "blue") +
theme_economist()
## Not run:
## The Economist sets charts in "Econ Sans", which is not publicly
## available. Any narrow humanist sans is a reasonable substitute, if it is
## installed on your system.
p + theme_economist(base_family = "Roboto Condensed") +
scale_colour_economist()
## End(Not run)
ggplot theme based on old Excel plots
Description
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.
Usage
theme_excel(base_size = 12, base_family = "", horizontal = TRUE)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
horizontal |
|
Value
An object of class theme().
See Also
Other themes excel:
theme_excel_new()
Examples
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()
ggplot theme similar to current Excel plot defaults
Description
Theme for ggplot2 that is similar to the default style of charts in current versions of Microsoft Excel.
Usage
theme_excel_new(base_size = 9, base_family = "sans")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Details
Excel derives its chart greys from the theme's tx1 colour
by luminance transform rather than hardcoding them. Since tx1 is
black in every built-in Office theme, these greys—"#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.
Value
An object of class theme().
See Also
Other themes excel:
theme_excel()
Examples
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 Few's "Practical Rules for Using Color in Charts"
Description
Theme based on the rules and examples from Stephen Few's Show Me the Numbers and "Practical Rules for Using Color in Charts".
Usage
theme_few(base_size = 12, base_family = "")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Value
A ggplot2 theme object (class theme).
References
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.
Examples
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 FiveThirtyEight plots
Description
Theme inspired by the plots from FiveThirtyEight.com.
Usage
theme_fivethirtyeight(base_size = 12, base_family = "sans")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Value
A ggplot2 theme object (class theme).
Examples
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()
p
Foundation Theme
Description
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 theme_gray() or theme_bw(),
because those themes define elements deep in the hierarchy.
Usage
theme_foundation(
base_size = 12,
base_family = "",
ink = "black",
paper = "white",
accent = "#3366FF"
)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
ink, paper, accent |
colour for foreground, background, and accented elements respectively. |
Details
This theme takes 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 colour 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.
Value
A ggplot2 theme object (class theme).
See Also
Other themes:
theme_base(),
theme_clean(),
theme_igray(),
theme_par(),
theme_solid()
Examples
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 with Google Docs Chart defaults
Description
Theme similar to the default look of charts in Google Docs.
Usage
theme_gdocs(base_size = 12, base_family = "sans")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Value
A ggplot2 theme object (class theme).
Examples
library("ggplot2")
p <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
facet_wrap(~am)
p + theme_gdocs() + scale_color_gdocs()
Highcharts Theme
Description
Themes based on Highcharts plots.
Usage
theme_hc(
base_size = 12,
base_family = "sans",
style = c("default", "default_dark", "darkunica", "grid_light", "sand_signika"),
bgcolor = NULL
)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
style |
The Highcharts theme to use. One of
|
bgcolor |
Deprecated |
Details
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 colours, 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.
Value
A ggplot2 theme object (class theme).
References
https://www.highcharts.com/demo/highcharts/line-chart
Examples
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")
Inverse gray theme
Description
Theme with white panel and gray background.
Usage
theme_igray(base_size = 12, base_family = "")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Value
A ggplot2 theme object (class theme).
Details
This theme inverts the colors in the theme_gray(), a
white panel and a light gray area around it. This keeps a white
background for the color scales like 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 theme_gray(). This is
similar to the style of plots in Stata and Tableau.
See Also
theme_gray(),
theme_bw()
Other themes:
theme_base(),
theme_clean(),
theme_foundation(),
theme_par(),
theme_solid()
Examples
library("ggplot2")
p <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
facet_wrap(~am)
p + theme_igray()
Clean theme for maps
Description
A clean theme that is good for displaying maps from
geom_map().
Usage
theme_map(base_size = 9, base_family = "")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Value
A ggplot2 theme object (class theme).
Examples
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 with Apple Numbers chart defaults
Description
Theme similar to the default look of charts in Apple Numbers.
Usage
theme_numbers(base_size = 12, base_family = "sans")
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Details
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.
Value
A ggplot2 theme object (class theme).
Examples
library("ggplot2")
p <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
facet_wrap(~am)
p + theme_numbers() + scale_color_numbers()
A ggplot theme originated from the pander package
Description
The pander 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.
Usage
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
)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
nomargin |
suppress the white space around the plot (boolean) |
ff |
font family, like |
fc |
font color (name or hexa code) |
fs |
font size (integer). Deprecated: use |
gM |
major grid (boolean) |
gm |
minor grid (boolean) |
gc |
grid color (name or hexa code) |
gl |
grid line type ( |
boxes |
to render a border around the plot or not |
bc |
background color (name or hexa code) |
pc |
panel background color (name or hexa code) |
lp |
legend position |
axis |
axis angle as defined in |
Value
A ggplot2 theme object (class theme).
Examples
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 par().
Not all par() parameters, are supported, and not all are relevant to
ggplot2 themes.
Description
Currently this theme uses the values of the parameters:
"code", ""ps"", "code" "family", "fg",
"bg", "adj", "font", "cex.axis",
"cex.lab", "cex.main", "cex.sub", "col.axis",
"col.lab", "col.main", "col.sub", "font",
"font.axis", "font.lab", "font.main",
"font.sub", "las", "lend",
"lheight", "lty", "mar", "ps", "tcl",
"tck", "xaxt", "yaxt".
Usage
theme_par(base_size = par()$ps, base_family = par()$family)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
Details
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.
Value
A ggplot2 theme object (class theme).
See Also
Other themes:
theme_base(),
theme_clean(),
theme_foundation(),
theme_igray(),
theme_solid()
Examples
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)
ggplot color themes based on the Solarized palette
Description
See https://ethanschoonover.com/solarized/ for a description of the Solarized palette.
Usage
theme_solarized(base_size = 12, base_family = "", light = TRUE)
theme_solarized_2(base_size = 12, base_family = "", light = TRUE)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
light |
|
Details
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
to theme_bw(), while theme_solarized_2() is
similar to theme_gray().
Value
A ggplot2 theme object (class theme).
Examples
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 with nothing other than a background color
Description
Theme that removes all non-geom elements (lines, text, etc), This theme is when only the geometric objects are desired.
Usage
theme_solid(base_size = 12, base_family = "", fill = NA)
Arguments
base_size |
Base font size. |
base_family |
Ignored, kept for consistency with |
fill |
Background color of the plot. |
Value
A ggplot2 theme object (class theme).
See Also
Other themes:
theme_base(),
theme_clean(),
theme_foundation(),
theme_igray(),
theme_par()
Examples
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
Description
Themes based on Stata graph schemes
Usage
theme_stata(base_size = 11, base_family = "sans", scheme = NULL)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
scheme |
One of "stcolor", "stcolor_alt", "stmono1", "stmono2",
"stsj", "s2color", "s2mono", "s1color", "s1rcolor", "s1mono",
"s2manual", "s1manual", or "sj". If |
Details
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 guide_legend() rather than
the theme) and Stata's small default marker size (a geom default).
Value
A ggplot2 theme object (class theme).
References
https://www.stata.com/help.cgi?schemes
Examples
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")
Tufte Maximal Data, Minimal Ink Theme
Description
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 geom_rug() or
geom_rangeframe().
Usage
theme_tufte(base_size = 11, base_family = "serif", ticks = TRUE)
Arguments
base_size |
base font size, given in pts. |
base_family |
base font family |
ticks |
|
Value
A ggplot2 theme object (class theme).
Note
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.
References
Tufte, Edward R. (2001) The Visual Display of Quantitative Information, Chapter 6.
See Also
Other tufte:
extended_range_breaks_(),
geom_rangeframe(),
geom_tufteboxplot()
Examples
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)
Wall Street Journal theme
Description
Theme based on the plots in The Wall Street Journal.
Usage
theme_wsj(
base_size = 12,
color = "brown",
base_family = "sans",
title_family = "mono"
)
Arguments
base_size |
base font size, given in pts. |
color |
The background color of plot. One of |
base_family |
base font family |
title_family |
Plot title font family. |
Details
This theme should be used with scale_color_wsj().
Value
A ggplot2 theme object (class theme).
References
https://pinterest.com/wsjgraphics/wsj-graphics/
Examples
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")
Shape palette from Tremmel (1995) (discrete)
Description
Based on experiments Tremmel (1995) suggests the following shape palettes:
Usage
tremmel_shape_pal(overlap = FALSE, alt = FALSE)
Arguments
overlap |
use an empty circle instead of a solid circle when
|
alt |
If |
Details
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.
Value
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
discrete_scale().
References
Tremmel, Lothar, (1995) "The Visual Separability of Plotting Symbols in Scatterplots" Journal of Computational and Graphical Statistics, https://www.jstor.org/stable/1390760
See Also
Other shapes:
circlefill_shape_pal(),
cleveland_shape_pal(),
scale_shape_circlefill(),
scale_shape_cleveland(),
scale_shape_tremmel()
Examples
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))
Wall Street Journal color palette (discrete)
Description
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.
Usage
wsj_pal(palette = "colors6")
Arguments
palette |
|
Value
A palette function. It takes the number of colours n and returns a character vector of n
hex colours, and can be used as the palette argument of discrete_scale().
Palettes
The following palettes are defined,
- rgby
Red/Green/Blue/Yellow theme.
- red_green
Green/red two-color scale for good/bad.
- green_black
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.
See Also
Other colour wsj:
scale_colour_wsj()
Examples
wsj_pal()(6)
scales::show_col(wsj_pal("rgby")(4))