R-paintingr-调色板
"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()
![](https://img.haomeiwen.com/i17679619/f814ba5902891295.png)
使用 paint_palette("name")
获取某个调色板的颜色
paintingr
提供以下调色板
调色板
Pearlgirl
Girl with a Pearl Earring - Johannes Vermeer (1665), Source
paint_palette("Pearlgirl")
![](https://img.haomeiwen.com/i17679619/ca7a85c2c5fa5bf8.png)
Splash
A Bigger Splash - David Hockney (1967), Source
paint_palette("Splash")
![](https://img.haomeiwen.com/i17679619/8a18adbca471dc9c.png)
Autumn
Autumn at Oirase - Kawase Hasui (1933), Source
paint_palette("Autumn")
![](https://img.haomeiwen.com/i17679619/64c4b702ce0d2861.png)
Villeneuve
Matin à Villeneuve - Henri Biva (1905), Source
paint_palette("Villeneuve")
![](https://img.haomeiwen.com/i17679619/d00ba304de5d9d07.png)
Ophelia
Ophelia - John Everett Millais (1851-1852), Source
paint_palette("Ophelia")
![](https://img.haomeiwen.com/i17679619/5b8dbd267276daae.png)
Kitchen
Kitchen (Detail 2) - Liza Lou (1991–1996), Source
paint_palette("Kitchen")
![](https://img.haomeiwen.com/i17679619/b9e65fe2958263ac.png)
Spring
SPRING BY THE SEINE - Claude Monet (1875), Source
paint_palette("Spring")
![](https://img.haomeiwen.com/i17679619/57894ff25d119ceb.png)
Strawberries
Strawberries - Édouard Manet (1882), Source
paint_palette("Strawberries")
![](https://img.haomeiwen.com/i17679619/07ef9b4f12af64df.png)
Seascape
Seascape at Saintes-Maries - Vincent van Gogh (1888), Source
paint_palette("Seascape")
![](https://img.haomeiwen.com/i17679619/244835dd334b5bad.png)
Twilight
Twilight, Venice - Claude Monet (1908), Source
paint_palette("Twilight")
![](https://img.haomeiwen.com/i17679619/1b2872d487997b6a.png)
Abstract
Abstract Composition - Jessica Dismorr (1915), Source
paint_palette("Abstract")
![](https://img.haomeiwen.com/i17679619/01c6aef1fc4a5780.png)
一些例子
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()
![](https://img.haomeiwen.com/i17679619/7bbea5163517c135.png)
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"))
![](https://img.haomeiwen.com/i17679619/17c7047c29e664dc.png)
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"))
![](https://img.haomeiwen.com/i17679619/57945ef817805893.png)
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"))
![](https://img.haomeiwen.com/i17679619/9309e96fa2e672a6.png)
Barplot
ggplot(mpg, aes(x = class, fill = drv)) +
geom_bar() +
theme_classic() +
scale_fill_manual(values = paint_palette("Ophelia"))
![](https://img.haomeiwen.com/i17679619/72ed22417814a3d7.png)