"The greatest value of a picture is when it forces us to notice what we never expected to see." - John Tukey
颜色是数据可视化中的一个重要环节。
一个好的配色可以更生动地传达我们的观点,强调我们要强调的内容。
从油画当中汲取了一些配色方案,写成了一个R包 paintingr
(https://github.com/thereallda/paintingr)
欢迎使用R画图的朋友给点意见和建议!
paintingr
paintingr
提供了一系列油画来源的调色板
paintingr
的代码结构参考了wesanderson 包
其中的部分调色板配色来自于 三三两两的色盘
安装
目前可以通过github安装开发版本:
# install.packages("devtools")
devtools::install_github("thereallda/paintingr")
后续会考虑发布到 CRAN 上
使用
可以通过 display_all_palettes()
查看当前提供的调色板
library(paintingr)
# display all palettes
display_all_palettes()

使用 paint_palette("name")
获取某个调色板的颜色
paintingr
提供以下调色板
调色板
Pearlgirl
Girl with a Pearl Earring - Johannes Vermeer (1665), Source
paint_palette("Pearlgirl")

Splash
A Bigger Splash - David Hockney (1967), Source
paint_palette("Splash")

Autumn
Autumn at Oirase - Kawase Hasui (1933), Source
paint_palette("Autumn")

Villeneuve
Matin à Villeneuve - Henri Biva (1905), Source
paint_palette("Villeneuve")

Ophelia
Ophelia - John Everett Millais (1851-1852), Source
paint_palette("Ophelia")

Kitchen
Kitchen (Detail 2) - Liza Lou (1991–1996), Source
paint_palette("Kitchen")

Spring
SPRING BY THE SEINE - Claude Monet (1875), Source
paint_palette("Spring")

Strawberries
Strawberries - Édouard Manet (1882), Source
paint_palette("Strawberries")

Seascape
Seascape at Saintes-Maries - Vincent van Gogh (1888), Source
paint_palette("Seascape")

Twilight
Twilight, Venice - Claude Monet (1908), Source
paint_palette("Twilight")

Abstract
Abstract Composition - Jessica Dismorr (1915), Source
paint_palette("Abstract")

一些例子
ggplot2
-based examples
Heatmap
如果你需要更多的颜色(n > 5/6)时,可以使用 type="continuous"
参数,并指定需要的颜色个数
library(paintingr)
library(ggplot2)
# Dummy data
x <- LETTERS[1:20]
y <- paste0("var", seq(1,20))
data <- expand.grid(X=x, Y=y)
data$Z <- seq(1,20)+runif(400, 0, 5)
# Heatmap
pal <- paint_palette("Autumn", n=100, type="continuous")
ggplot(data, aes(X, Y, fill= Z)) +
geom_tile() +
scale_fill_gradientn(colours = pal) +
scale_x_discrete(expand = c(0, 0)) +
scale_y_discrete(expand = c(0, 0)) +
coord_equal()

Boxplot
# use iris data from `ggplot2` for demonstration
data(iris)
ggplot(iris, aes(Species, Sepal.Length)) +
geom_boxplot(aes(fill = Species)) +
theme_classic() +
theme(legend.position = "top") +
scale_fill_manual(values = paint_palette("Villeneuve"))

Scatter
# Scatter
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point(aes(color = Species)) +
theme_classic() +
theme(legend.position = "top") +
scale_color_manual(values = paint_palette("Kitchen"))

Violin plot
data(mpg)
# violin plot with 7 colors, Spring palette only have six colors add one more
ggplot(mpg, aes(x=class, y=hwy, fill=class)) +
geom_violin() +
theme_classic() +
scale_fill_manual(values = c(paint_palette("Spring", n=6), "black"))

Barplot
ggplot(mpg, aes(x = class, fill = drv)) +
geom_bar() +
theme_classic() +
scale_fill_manual(values = paint_palette("Ophelia"))

网友评论