【问题标题】:Wide Range of the same Color in RR中相同颜色的广泛范围
【发布时间】:2014-01-29 09:51:12
【问题描述】:

是否可以创建大量不同种类的“红色”颜色。为了更好地理解,我期待跟随,但我希望使用“红色”或“红黑”而不是灰色。

mypalette <- rev(grey.colors(10000, start = 0.1, end = 0.5, gamma = 4))
plot(1:length(mypalette),1:length(mypalette), col=mypalette, pch=16)

我知道的颜色包颜色范围有限。任何想法将不胜感激。

【问题讨论】:

  • color.gradient(c(1, 1), c(1, 0), c(0, 0), nslices = 10) 来自plotrix

标签: r colors color-palette


【解决方案1】:

如果我了解您想要什么,请尝试colorRampPalette。它返回一个函数,输出您指定的两种颜色之间的请求数量。

reds <- colorRampPalette(c("black","red"))
reds(5)
[1] "#000000" "#3F0000" "#7F0000" "#BF0000" "#FF0000"

【讨论】:

  • 这就是我想要的!非常感谢。
【解决方案2】:

这里有一些ggplot 替代方案

library(ggplot2)
df <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100), z2 = factor(1:5))

# colour set by continuous variable
ggplot(data = df, aes(x = x, y = y, colour = z)) +
  geom_point() +
  scale_colour_gradient(low = "red", high = "white")

library(RColorBrewer)
ggplot(data = df, aes(x = x, y = y, colour = z)) +
  geom_point() +
  scale_colour_gradientn(colours = brewer.pal(5, "Reds"))

# colour set by discrete variable
ggplot(data = df, aes(x = x, y = y, colour = z2)) +
  geom_point() +
  scale_colour_brewer(palette = "Reds")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2021-12-27
    • 2021-07-30
    • 1970-01-01
    相关资源
    最近更新 更多