R:Scale_Colour_Manual不工作?

时间:2017-03-29 19:37:02

标签: r ggplot2 boxplot

出于某种原因,我无法让scale_colour_manual为我的geom_boxplot工作。我想把白天(0)变为黄色,将夜晚(1)变为黑色。

data <- read.csv(path)

cleandata <- data[1:66, 1:11]

install.packages('ggplot2')

library(ggplot2)

nd <- ggplot(cleandata, aes(factor(time), vigilance, fill=factor(time)))

nd+geom_boxplot(aes(fill = factor(time))) +
theme_bw() + 
theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
xlab("Time of Day") +
ylab("Percentage of Group Vigilant") +
stat_boxplot(geom="errorbar") +
scale_colour_manual(values = c('yellow', 'black'), labels = c("0" = "Day", "1" = "Night")) +
facet_grid(~group)



    number  observer    site    date    time    group   species size    males   juveniles   vigilance
1   Jaz pete    403 0   mammal  Whitebearded Gnu    12  0.25    0.00    41.67
2   Jaz pete    403 0   mammal  Impala  16  0.25    0.13    16.35
3   Jaz djuma   403 1   mammal  Nyala   3   1.00    0.00    58.97
4   Jaz djuma   503 0   mammal  Nyala   12  0.17    0.08    64.74
5   Jaz pete    503 0   mammal  Impala  16  0.63    0.00    60.58
6   Jaz djuma   603 0   bird    Saddlebilled Stork  3   0.00    0.00    56.41
7   Jaz djuma   603 1   bird    Black Stork 11  0.82    0.00    58.74
8   Jaz djuma   903 0   bird    Saddlebilled Stork  3   1.00    0.00    51.28

0 个答案:

没有答案