10 November 2021
library(ggplot2)
library(dichromat)
## palettes etc.
library(viridis)
library(cividis) ## https://github.com/marcosci/cividis
library(colorspace)
library(RColorBrewer)
library(cowplot)
library(colorBlindness)
head(colours())
## [1] "white" "aliceblue" "antiquewhite" "antiquewhite1"
## [5] "antiquewhite2" "antiquewhite3"
#RRGGBB
(additive, hexadecimal, colour specification: e.g. #FFFFFF
= white, #FF0000
= red (sometimes a fourth hex value indicates alpha-transparency)adjustcolor
function can help you fiddle a color that you already likeapropos("colo|rgb"), ignore.case = FALSE)
brings up a whole bunch of relevant stuff (the pipe means “or” here)dd <- data.frame(x=1:9)
ggplot(dd,aes(x=x,y=1,alpha=x)) +
geom_point(size=10,colour="red") +
coord_fixed(ratio=5)+theme_void()
ggplot(dd,aes(x=x,y=1))+
geom_point(size=10,aes(colour=x))+
scale_colour_gradient(low="lightgray",high="red")+
coord_fixed(ratio=5)+theme_void()
display.brewer.all()
Old Faithful data (duration vs waiting time)
HSV, grayscale, HSV heat, HCL heat
(left) hue varies, constant saturation & value; (right) hue varies, constant chroma & luminance
By Holger kkk Everding - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=38366968
png("pix/colorspace.png")
hcl_palettes(plot=TRUE)
dev.off()
png("pix/colordemo.png")
par(mfrow = c(3, 3), mar = c(1,1,1,1))
cl <- sequential_hcl(5, "Heat")
for (i in c("map", "heatmap", "scatter", "spine",
"bar", "pie", "perspective", "mosaic", "lines")) {
demoplot(cl, type = i)
}
dev.off()
Why stick to a single path in the colour space? Why not fill an area?
hues
, randomcoloR
(randomColor()
!)
par(mfrow=c(2,2),mar=c(1,1,1,1))
p <- brewer.pal("Set1",n=6)
pie(rep(1,6), col=p,main="ColourBrewer Set1")
pie(rep(1,6), col = dichromat(p))
p2 <- brewer.pal("Dark2",n=6)
pie(rep(1,6), col=p2, main="ColourBrewer Dark2")
pie(rep(1,6), col = dichromat(p2))
colorblindr
(clauswilke/colorblindr
), colorBlindness
(CRAN)colorBlindness::displayAvailablePalette(color="white")
upload an image or point to a URL
Colour appearance depends on neighbours
(ggplot(dd,aes(x=x,y=1,colour=factor(x)))
+ geom_point(size=10)
+ coord_fixed(ratio=5)
+ theme(legend.position="none")
+ scale_colour_manual(values=topo.colors(9))
+ theme_void()
+ theme(legend.position="none")
)
library(ggplot2); library(colorspace); library(viridis)
length(apropos("scale_colour_"))
## [1] 36
Zeileis, Achim, Jason C. Fisher, Kurt Hornik, Ross Ihaka, Claire D. McWhite, Paul Murrell, Reto Stauffer, and Claus O. Wilke. 2019. “Colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.” arXiv:1903.06490, March. http://arxiv.org/abs/1903.06490.
Zeileis, Achim, Kurt Hornik, and Paul Murrell. 2009. “Escaping RGBland: Selecting Colors for Statistical Graphics.” Computational Statistics & Data Analysis 53 (9): 3259–70. https://doi.org/10.1016/j.csda.2008.11.033.