I'm trying to create several graphs using ggplot. The graphs are a series of bar graphs that together describe a line as well EXAMPLE (BTW, yes I realize the color palette is ugly, it's color-blind friendly which is important for my audience)
My issue is that I need to make several of these graphs and I want the colors to stay consistent across all of them. Since the "Type" variable comes up in different orders across the several datasets I'm going to be using, I need to manually set a color for each type. I thought that this question : How to manually fill colors in a ggplot2 histogram would have the answer, but when I try that, it changes the names in the legend to the hex definition of the color, but the colors themselves go back to ggplot's default palette.
Here's the code I have so far:
cbbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
ggplot()+
scale_fill_manual(values=cbbPalette)+
geom_bar(data=subset(eten, Type=="Waste Wood"), aes(x=Tprod, y=acost, fill=cbbPalette[1], width=MGGEY+25), stat="identity")+
geom_bar(data=subset(eten, Type=="Agricultural Residue"), aes(x=Tprod, y=acost, fill=cbbPalette[2], width=MGGEY+25), stat="identity")+
geom_bar(data=subset(eten, Type=="Forest Residue"), aes(x=Tprod, y=acost, fill=cbbPalette[3], width=MGGEY+25), stat="identity")+
geom_bar(data=subset(eten, Type=="Herbaceous Energy Crop"), aes(x=Tprod, y=acost, fill=cbbPalette[4], width=MGGEY+25), stat="identity")+
geom_bar(data=subset(eten, Type=="MSW"), aes(x=Tprod, y=acost, fill=cbbPalette[5], width=MGGEY+25), stat="identity")+
scale_y_continuous("Average Cost", labels = dollar, expand=c(0,0))+
scale_x_continuous("Million Gallons of Gasoline Equivalent", expand=c(0,0))+
theme(legend.position="bottom", panel.background=element_rect(colour = NA, fill = "white"), axis.line=element_line(), panel.grid.major.y=element_line(colour="black"), panel.grid.minor=element_blank())
My level of R expertise is fairly low, so I may be missing something simple, but I can't get it to work on my own. Thanks in advance for the help.
Update: I inadvertently pasted an incorrect version of my code, the "fill" commands are back to my best guess. An example dataset is here.
See Question&Answers more detail:
os