ggplot2:点颜色不会自动更改

ggplot2: Dot colors are NOT automatically changed

我正在使用以下代码制作图形:

d1 <- data.frame(time    = c(0,15,60,120),
                 number = c(0, 5, 5, 10, 0, 20, 20, 25),
                 arm     = c(rep("A",4), rep("B",4)))


ggplot(d1, aes(x = time, y = number, color = arm)) +
  scale_color_grey(start = 0.6, end = 0.2, guide = F) +
  geom_point(aes(shape = arm), 
             size = 3, 
             position = position_dodge(width=0)) +
  geom_line(aes(), 
            position = position_dodge(width=0)) +
  scale_x_continuous(name = "Time",breaks=c(0,15,60,120)) + 
  scale_shape_discrete(name = " ", 
                       labels = c("A type","B type")) +
  theme(axis.title.x=element_text(size=9),
        legend.position = "top",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) + 
  ylab("People")
  

不过,我注意到Type A的圆点颜色不是灰色,而是黑色。
无论如何,我可以相应地手动更改它吗?
如果可能的话,我想保留函数“scale_color_grey”。

谢谢!!

只需确保您同时拥有比例尺和颜色指南,并确保名称和标签相匹配。这应该有效

ggplot(d1, aes(x = time, y = number, color = arm)) +
  scale_color_grey(start = 0.6, end = 0.2, name = " ", labels = c("A type","B type")) + 
  scale_shape_discrete(name = " ", labels = c("A type","B type")) +
  ...

这会将两个图例合并为一个。