ggplot: recommended colour palettes also distinguishable for B&W printing?
Use http://colorbrewer2.org/ and only show colour schemes that are printer friendly.
Also see scale_fill_grey
.
Currently it's not possible to used hash lines due to a limitation in the underlying grid
drawing package.
Colour palette that works in colour and in greyscale?
I think it could help to see the palettes in both raw and black&white version, like this (or with other palettes)
R color palettes for many data classes
Try '?colorRampPalette' and make your own function.
How to produce a heatmap with ggplot2?
To be honest @dr.bunsen - your example above was poorly reproducable and you didn't read the first part of the tutorial that you linked. Here is probably what you are looking for:
library(reshape)
library(ggplot2)
library(scales)
data <- structure(list(people = structure(c(2L, 3L, 1L, 4L),
.Label = c("bill", "mike", "sue", "ted"),
class = "factor"),
apple = c(1L, 0L, 3L, 1L),
orange = c(0L, 0L, 3L, 1L),
peach = c(6L, 1L, 1L, 0L)),
.Names = c("people", "apple", "orange", "peach"),
class = "data.frame",
row.names = c(NA, -4L))
data.m <- melt(data)
data.m <- ddply(data.m, .(variable), transform, rescale = rescale(value))
p <- ggplot(data.m, aes(variable, people)) +
geom_tile(aes(fill = rescale), colour = "white")
p + scale_fill_gradient(low = "white", high = "steelblue")
R Plot Color Combinations that Are Colorblind Accessible
Okabe-Ito palette
The palette shown in the question is also known as the Okabe-Ito palette as suggested by Okabe & Ito (2008). Since version 4.0.0, base R provides a new palette.colors()
where this palette is actually the default:
palette.colors(palette = "Okabe-Ito")
## black orange skyblue bluishgreen yellow
## "#000000" "#E69F00" "#56B4E9" "#009E73" "#F0E442"
## blue vermillion reddishpurple gray
## "#0072B2" "#D55E00" "#CC79A7" "#999999"
Qualitative palettes in base R
Along with this palette, various other qualitative palettes are easily available in base R. Specifically, the new default palette (called "R4"
) has also been designed to be rather robust under color vision deficiencies. See this blog post for further details:
- Zeileis, Murrell, Maechler, Sarkar (2019). "A New palette() for R." The R Blog.
Sequential and diverging palettes in base R
In addition to the qualitative palettes above, base R also has a new function hcl.colors()
since version 3.6.0 that makes many sequential and diverging palettes available that are also robust under color vision deficiencies. It provides approximations (derived using the hue-chroma-luminance color model) to many palettes from ColorBrewer.org, viridis, CARTO colors, Crameri's scientific colors etc. The default is the popular viridis palette. The following blog post provides more details and the paper about the colorspace
package explains more related/underlying work.
- Zeileis, Murrell (2019). "HCL-Based Color Palettes in grDevices." The R Blog.
- Zeileis, Fisher, Hornik, Ihaka, McWhite, Murrell, Stauffer, Wilke (2020). "colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes." Journal of Statistical Software.
Related Topics
R Shiny: How to Change The Background Color of The Header
How to Split a Dataframe Column by The First Instance of a Character in Its Values
Convert a Row of a Data Frame to a Simple Vector in R
How to Add Geo-Spatial Connections on a Ggplot Map
How to Find The Indices Where There Are N Consecutive Zeroes in a Row
Split Character Vector into Sentences
How to Plot Grid Plots on a Same Page
Passing Ellipsis Arguments to Map Function Purrr Package, R
How to Align or Center The Bars of a Histogram on The X Axis
Shapefile to Raster Conversion in R
Importing Many Files at The Same Time and Adding Id Indicator
How to Predict Survival Probabilities in R
Ggplot and Axis Numbers and Labels
Get Expression That Evaluated to Dot in Function Called by 'Magrittr' Pipe
How to Perform Single Factor Anova in R with Samples Organized by Column