Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中相同颜色的宽范围_R_Colors_Color Palette - Fatal编程技术网

R中相同颜色的宽范围

R中相同颜色的宽范围,r,colors,color-palette,R,Colors,Color Palette,是否有可能创造大量不同种类的“红色”颜色。为了更好的理解,我期待下面的内容,但我希望有“红色”或“红黑”,而不是灰色 mypalette如果我了解您想要什么,请尝试colorRampPalette。它返回一个函数,输出指定的两种颜色之间所需的颜色数 reds <- colorRampPalette(c("black","red")) reds(5) [1] "#000000" "#3F0000" "#7F0000" "#BF0000" "#FF0000" reds以下是一些ggplot替

是否有可能创造大量不同种类的“红色”颜色。为了更好的理解,我期待下面的内容,但我希望有“红色”或“红黑”,而不是灰色


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

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

reds以下是一些
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")


color.gradient(c(1,1),c(1,0),c(0,0),nslices=10)
from
plotrix
package这正是我想要的!谢谢。
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")