此文为自己翻译,原文链接请看How to expand color palette with ggplot and RColorBrewer
直方图(histogram)和柱状图(bar)是数据分析展示的一部分。如果图是由R语言ggplot2包中函数geom_histogram()或者geom_bar()来制作,则柱状图看起来是这样的:
library(ggplot2)
ggplot(mtcars, aes(factor(cyl), fill=factor(cyl))) +
geom_bar()
ggplot函数的优雅在于对可视化公式简单而紧凑的表达,同时隐藏了默认情况下许多假设选项。隐藏并不意味着缺乏,因为大多数选择只是一步之遥。例如,对于颜色选择,使用scale函数族中的其中一种选择scale_fill_brewer():
ggplot(mtcars, aes(factor(cyl), fill=factor(cyl))) +
geom_bar() +
scale_fill_brewer()