Reputation: 2368
I have a dataset of means of ratings for members of a bunch of different groups. I have graphed the top and bottom 3 means of each group in decreasing order. However, when I'm trying to set the color manually, I get nowhere. I want the first three to be one color (the columns of fame, if you will) and the last three to be another (the columns of shame). However, when I try to specify those colors using:
cbbPalette <- c("#60BD68", "#60BD68", "#60BD68", "#F15854", "#F15854", "#F15854")
tb3color <- scale_fill_manual(values=c(cbbPalette))
It does precisely nothing. No error, no message, nothing. I'm wondering what I'm doing wrong here! I have included a testset that's treated exactly the same thing that I've done.
library(data.table)
library(ggplot2)
library(plyr)
options(digits = 4)
graphOptions <- theme(axis.text.x=element_text(size = 10, angle = 40, vjust = 1, hjust = 1.01))
cbbPalette <- c("#60BD68", "#60BD68", "#60BD68", "#F15854", "#F15854", "#F15854")
tb3color <- scale_fill_manual(values=c(cbbPalette))
QSPQS <- geom_hline(yintercept=seq(85, 95, by=5), color="#F15854")
WASPQS <- geom_hline(yintercept=seq(3, 3.5, by=.25), color="#F15854")
testset <- data.table(group = c("B", "E", "F", "M", "I", "J", "A", "D", "K", "G", "L", "C", "H"), numbers = c(87.33, 89.67, 89.92, 90.08, 90.96, 91.03, 92.04, 92.94, 93.49, 94.21, 94.31, 94.68, 95.56))
testset1 <- rbind(head(testset,3), tail(testset,3))
setnames(testset1,2,"Rating")
testset2 <- transform(testset1, group = reorder(group, order(Rating, decreasing = TRUE)))
ggplot(testset2, aes(x=group, y=Rating)) + geom_bar(stat="identity") + coord_cartesian(ylim = c(70, 100)) + QSPQS + tb3color
Thanks in advance!
Upvotes: 3
Views: 1106
Reputation: 68849
You have to add a fill
aesthetic (aes(fill=...)
):
ggplot(testset2, aes(x=group, y=Rating, fill=group)) +
geom_bar(stat="identity") +
coord_cartesian(ylim = c(70, 100)) + QSPQS + tb3color
Upvotes: 1