Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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 ggplot符号颜色方案错误_R_Ggplot2 - Fatal编程技术网

R ggplot符号颜色方案错误

R ggplot符号颜色方案错误,r,ggplot2,R,Ggplot2,我试图用连续的色标绘制点的散点图。不过,我正在设置自己的比例,因为我的数据不是线性的,而且我的大多数数据点都有相同的颜色(并且无法识别)和自动颜色比例 我现在的代码如下所示: cut.values <- c(4, 5, 5.5, 6.5, 7, 7.5) iris$cuts <- cut(iris$Sepal.Length, cut.values) library(dplyr) pick <- function(condition){ function(d) d %>

我试图用连续的色标绘制点的散点图。不过,我正在设置自己的比例,因为我的数据不是线性的,而且我的大多数数据点都有相同的颜色(并且无法识别)和自动颜色比例

我现在的代码如下所示:

cut.values <- c(4, 5, 5.5, 6.5, 7, 7.5)
iris$cuts <- cut(iris$Sepal.Length, cut.values)
library(dplyr)
pick <- function(condition){
  function(d) d %>% filter_(condition)
}
ggplot(iris, aes(x=Petal.Length, y=Petal.Width, color = cuts), label = Sepal.Length) +
  geom_point(data = pick(~Species == "setosa"), size = 5, shape = 16, show.legend = F) +
  geom_point(data = pick(~Species == "versicolor"), size = 5, shape = 17, show.legend = F) +
  scale_color_brewer("", palette = "Spectral") +
  theme_bw() 
然而,这似乎改变了点的颜色,即使我使用的是相同的
“光谱”调色板
。命令的某个部分是否覆盖了我尝试使用的配色方案?使用
shape 21
22
时,如何保持相同的配色方案

(因为我使用
切割定义自己的色阶,所以我使用这个问题的第一个答案(),由于这使用了
调色板
缩放颜色酿酒器
命令,我必须坚持使用
缩放颜色酿酒器
来保持数据点和我用代码创建的色条之间的配色方案一致。)

缩放颜色酿酒器()
默认为美观的
“颜色”
。如果指定给
“填充”
,则打印调色板将正确

ggplot(iris, aes(x=Petal.Length, y=Petal.Width, fill = cuts), label = Sepal.Length) +
  geom_point(data = pick(~Species == "setosa"), size = 5, shape = 21, show.legend = F) +
  geom_point(data = pick(~Species == "versicolor"), size = 5, shape = 22, show.legend = F) +
  scale_color_brewer(palette = "Spectral", aesthetics = "fill") +
  theme_bw() 

嗨@Jen,哪个库是pick()函数?@M.Viking对不起,我的错!这是我添加的过滤功能,我编辑了问题,我看到了。美好的在此期间,我将调用更改为
…data=subset(iris,Species==“setosa”)…
。我想我已经找到答案了。。。仔细检查。啊,我明白为什么它现在使用不同的配色方案了,谢谢!!
ggplot(iris, aes(x=Petal.Length, y=Petal.Width, fill = cuts), label = Sepal.Length) +
  geom_point(data = pick(~Species == "setosa"), size = 5, shape = 21, show.legend = F) +
  geom_point(data = pick(~Species == "versicolor"), size = 5, shape = 22, show.legend = F) +
  scale_color_brewer(palette = "Spectral", aesthetics = "fill") +
  theme_bw()