且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更改geom_point中的颜色或ggplot中的线条

更新时间:2023-11-26 23:32:34

你可以使用scale_color_manual:

ggplot() + 
  geom_point(data = data, aes(x = time, y = y, color = sample),size=4) +
  scale_color_manual(values = c("A" = "black", "B" = "red"))

根据 OP 的评论,要获得与您可以执行的点具有相同颜色的线条:

Per OP's comment, to get lines with the same color as the points you could do:

ggplot(data = data, aes(x = time, y = y, color = sample)) + 
  geom_point(size=4) + 
  geom_line(aes(group = sample)) + 
  scale_color_manual(values = c("A" = "black", "B" = "red"))