Hoping to set two different color schemes for my ggplot based on a value in a certain column.
This is my data:
itemName = c("item1", "item2", "item3", "item4","item5", "item1", "item2", "item3", "item4", "item5")
MPindex = c(124, 118, 101, 112, 126, 124, 118, 101, 112, 126)
code = c("A", "A", "A", "A", "B", "A", "A", "A", "A", "B")
topTwo = c(55.6, 53,45.2, 50.2, 56.2, 55.6, 53, 45.2, 50.2, 56.2)
variable = c(4, 4, 4, 4, 4, 5, 5, 5, 5, 5)
value = c(37.2, 36.2, 31.4, 31.2, 34.2, 18.4, 16.8, 13.8, 19, 22)
testNew<-data.frame(itemName,MPindex,code,topTwo,variable,value)
And this is as close as I've gotten with the graph I want:
What I want though, is for the item with code=="B" to have different scale_fill_manual values. Note the order of the bars might change and the itemNames might change since this is reactive within a shiny app, so rather than manually setting item5 bar to be different, I really need it to go off of the "code" column.
Current graph code:
p14 = ggplot(data = testNew, aes(x=reorder(itemName,-MPindex),y=value,fill=variable))+blank_theme+
geom_bar(stat="identity")+geom_text(aes(label=paste(value,"%")),vjust=1.2,colour='white')+theme(axis.text.x = element_text(angle = 45,hjust=1.00,vjust = 1.15))+
xlab("")+scale_fill_manual(values = c("#33CCCC","#00A499"))
blank_theme <- theme_minimal()+
theme(
axis.text.y = element_blank(),
axis.title.y = element_blank(),
panel.border = element_blank(),
panel.grid=element_blank(),
axis.ticks = element_blank(),
plot.title=element_text(size=14, face="bold")
)
p14
And I want the code=="B" item to always have scale_fill_manual(values=c("lightgrey","grey").
Thanks in advance! :)