Abstract
如何给图表配色是设计人员的主要内容,对于数据分析人员,重点在于对数据的处理加工,稍微了解一些设计知识即可。如何不像深入了解设计知识,一个好的办法是搜索和精选好的商业图表案例,用取色器取出它们的配色,运用到自己的图表中。本文重点结合ggthemes和ggtech借鉴商业媒体图表的成功配色方案。
近年来,R语言开始流行,我也了解了一下R语言里ggplot2的作图,知道了ggthemes
主题包。它将一些期刊、软件的图表风格进行了整理,做成扩展包,方便地格式化出不同风格的图表.
ggthemes有多种风格的主题,其中最有商务气质的当属 wsj
和 economist
主题,也就是华尔街日报和经济学人的风格。这一篇帖子,就是要从ggthemes里提取华尔街日报的图表配色方案。
iris %>%
ggplot(aes(x = Sepal.Length,Sepal.Width,col = Species)) +
geom_point() +
ggthemes::theme_wsj() -> p
p
scale_fill_wsj()
设置序列的填充颜色,有5种参数,分别是 colors6
、rgby
、red_green
、black_green
、dem_rep
五组颜色,显示效果如下。
theme_wsj()
里面可以设置图表的背景色,有4种参数,分别是 brown
、gray
、green
、blue
,显示效果如下。序列颜色和背景颜色可以有不同的搭配组合。
## $rgby
## # A tibble: 4 x 2
## name value
## <chr> <chr>
## 1 yellow #d3ba68
## 2 red #d5695d
## 3 blue #5d8ca8
## 4 green #65a479
##
## $red_green
## # A tibble: 2 x 2
## name value
## <chr> <chr>
## 1 green #088158
## 2 red #ba2f2a
##
## $black_green
## # A tibble: 4 x 2
## name value
## <chr> <chr>
## 1 black #000000
## 2 gray #595959
## 3 ltgreen #59a77f
## 4 green #008856
##
## $dem_rep
## # A tibble: 3 x 2
## name value
## <chr> <chr>
## 1 blue #006a8e
## 2 red #b1283a
## 3 gray #a8a6a7
##
## $colors6
## # A tibble: 6 x 2
## name value
## <chr> <chr>
## 1 red #c72e29
## 2 blue #016392
## 3 gold #be9c2e
## 4 green #098154
## 5 orange #fb832d
## 6 black #000000
df <- data.frame(x=1:5, y=1:5)
p <- ggplot(df, aes(x=x, y=y, fill=factor(y))) +geom_bar(stat="identity")
p + scale_fill_economist() + theme_economist()
ggtech
也是 ggplot
的扩展主题包,它从著名科技公司 LOGO
取色做成图表主题
library(ggtech)
df <- data.frame(x=1:5, y=1:5)
df %>% ggplot(aes(x,y,fill = factor(x))) +
geom_col() +
theme_tech(theme="Airbnb") +
scale_fill_tech(theme="airbnb") +ggtitle("Airbnb, ExcelPro")
df <- data.frame(x=1:4, y=1:4)
df %>% ggplot(aes(x,y,fill = factor(x))) +
geom_col() +
theme_tech(theme="google") +
scale_fill_tech(theme="google") +ggtitle("google, ExcelPro")
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
df <- data.frame(x=1:4, y=1:4)
df %>% ggplot(aes(x,y,fill = factor(x))) +
geom_col() +
theme_tech(theme="twitter") +
scale_fill_tech(theme="twitter") +ggtitle("twitter, ExcelPro")
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列