如何根据存储在列中的颜色为ggplot着色

时间:2013-03-29 16:31:17

标签: r ggplot2

我希望有一个包含颜色名称的列,并且每个数据点都要根据此颜色进行着色。

traffic <- structure(list(Sequence = 1:7, Day = c("2013.03.29", "2013.03.28", "2013.03.27", "2013.03.26", "2013.03.25", "2013.03.24", "2013.03.21"), Performance = c("red", "red", "red", "red", "red", "yellow", "red")), .Names = c("Sequence", "Day", "Performance"), class = "data.frame", row.names = c(NA, -7L))

ggplot(traffic, aes(x=Day)) + 
geom_bar(aes(fill=Performance)) + 
scale_fill_manual(values=c("red","yellow", "green")) 

然而,在这种情况下,根据文件中可用的值(有时全部三个,有时只有一个或两个)来切换颜色。我试过了

scale_fill_manual(values=c("red"="red","yellow"="yellow", "green"="green"))

但这没有任何吸引力。

0 个答案:

没有答案