简体   繁体   English

R中的配色方案?

[英]Color schemes in R?

Does R have color palettes? R有调色板吗?

In other words, I am looking for an array of 6 or so color names that go well together in a graph or plot; 换句话说,我正在寻找一个由6个左右的颜色名称组成的数组,它们在图形或图形中很好地结合在一起; maybe there are some predefined schemes like that? 也许有一些像这样的预定义方案?

RColorBrewer , as mentioned by deinst, is very useful -- even though it was designed for maps rather than line charts. 正如deinst所提到的,RColorBrewer非常有用 - 即使它是专为地图而不是折线图设计的。

A number of other packages offer help with palettes: 许多其他包提供了调色板的帮助:

as can be seen from a quick query on 'palette' at rseek.org . rseek.org上的“调色板”快速查询中可以看出。

The easiest way to generate a palette is using generic functions from the basic grDevices package: 生成调色板的最简单方法是使用基本grDevices包中的泛型函数:

rainbow()
topo.colors()
terrain.colors()
heat.colors()

These are useful if the desired number of colors doesn't exceed 7-8. 如果所需的颜色数不超过7-8,这些都很有用。 The only necessary argument is the number of colors in palette. 唯一必要的参数是调色板中的颜色数量。

There is also gray() function which can be used to generate various schades of gray. 还有gray()函数,可用于生成各种灰度。

Or you could do something like: 或者你可以这样做:

pal <- colorRampPalette(c("red", "blue", "plum"))
barplot(t(as.matrix(mydf)), beside=TRUE, col=pal(3))

Look at the RColorBrewer package. 看看RColorBrewer包。 The colors are not named, but I think that they are close to what you are looking for. 颜色没有命名,但我认为它们接近你想要的。

Visit this page before using RColorBrewer. 在使用RColorBrewer之前访问此页面 Select the number of your data classes in the top and then define the nature of your data. 在顶部选择数据类的数量,然后定义数据的性质。 You may also find this page useful. 您可能还会发现此页面很有用。

No one mention this but look at palette function ( ?palette ) which define default pallet. 没人提这个,但看看定义默认托盘的palette功能( ?palette )。

palette()[1:6] gives you first six default colours. palette()[1:6]为您提供前六种默认颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM