2012-08-06 174 views
4

我有这样一个数据帧:如何更改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_hue,scale_shape_discretescale_fill_manual的不同方法,但没有任何成功。

回答

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

+0

谢谢@Chase! – 2012-08-06 20:37:26