如何在ggplot2中更改线条和形状颜色?

时间:2012-08-06 20:28:13

标签: r ggplot2

我有一个像这样的数据框:

x <- data.frame(time = c('1', '2', '3'), perc = c(0.2, 0.4, 0.6, 0.3, 0.55, 0.69, 0.2, 0.22, 0.35), type=c(rep('a', 3), rep('b', 3), rep('c', 3)))

并且想要制作这样的情节(下图)但是使用这些不同的颜色c('#0023a0', '#f9a635', '#bebec0')

ggplot(x, aes(time, perc, group=type, colour=type, shape=type)) + geom_point(size=4) + geom_line(size=1)

enter image description here

我已经尝试过使用scale_colour_huescale_shape_discretescale_fill_manual的不同方法,但没有取得任何成功。

1 个答案:

答案 0 :(得分:8)

你究竟尝试了什么?这似乎对我有用:

ggplot(x, aes(time, perc, group = type, pch = type, colour = type)) + 
  geom_point() +
  geom_line() +
  scale_colour_manual(values= c('#0023a0', '#f9a635', '#bebec0'))

enter image description here