n 个案例的 R Beautiful Colors

标签 r plot colors ggplot2

假设您想在 R 中绘制多个 n 不同的系列(使用 plot() 并不重要) 、ggplot2lattice。为了简单起见,我将使用 ggplot2),你如何选择一组漂亮的颜色(如可区分,但好看)。

我知道有多种方法,但我也想听听您的意见。

数据:

library(ggplot2) # for easy plots

n <- 10 # n cases for different numbers

set.seed(42)
dat <- data.frame(id = "A",
              group = 1:n,
              val = rnorm(n))

1。 GGplot 标准:

优点:可扩展

缺点:我觉得不是很漂亮

ggplot(dat, aes(x = id, y = val, fill = as.factor(group))) + 
  geom_bar(stat = "identity", position = "dodge")

GGPlot standard

2。彩虹:

优点:可扩展,即没有最大颜色数

ggplot(dat, aes(x = id, y = val, fill = as.factor(group))) + 
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = rainbow(n))

Rainbow

RColorBrewer

优点:颜色种类繁多

缺点:只限于最多12种颜色

参见 ColorBrewer2对于所有集合。

ggplot(dat, aes(x = id, y = val, fill = as.factor(group))) + 
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = brewer.pal(n, name = "BrBG")) # BrBG as an example

ColorBrewre BRBG

问题

当您有可能超过 10 个案例时,您如何设置绘图中的颜色?在指定颜色时,您设置了什么标准?

如果您想添加您认为重要的因素,请随时编辑这篇文章!

编辑:

与显示的图表相反,我处理时间序列,其中序列的颜色不包含任何信息,除了序列名称的标识

最佳答案

它可能不相关,但我几乎所有的事情都是手动完成的,使用这个网站: http://tools.medialab.sciences-po.fr/iwanthue/

理论选项卡很好地解释了所使用的方法。

关于n 个案例的 R Beautiful Colors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33256778/

相关文章:

r - 在 github 存储库中搜索定义给定函数的文件

r - Shiny 的应用程序 : Keep panels consistent in several views

python - 使用来自不同数据集的 for 循环进行绘图

colors - ffmpeg 颜色不透明度

r - 更改 ggplot2 中闪避条形图的颜色

r - 通过sparklyr将cassandra表导入spark - 可以仅选择某些列吗?

wolfram-mathematica - 匹配图例和绘图大小

Perl:将(x,y)像素绘制到单色位图的推荐方法

css - 在 IE 中更改选项文本颜色

r - DataTables 也应用列格式来过滤