I have a data set that documents the energy use of three buildings. I have a melted data frame that can be mimicked from the diamonds set:
data <- melt(diamonds[,c('depth','table','cut','color')],id=c('cut','color'))
Essentially, I have heating ('depth') and cooling ('table') data for each month('cut') from three different buildings (7 'color' factors). I would like to plot the three buildings (7 'color' factors) side by side in a bar plot for each month ('cut').
I want the bars representing either cooling ('table') or heating ('depth') to vary their shade based on the building ('color' factor) while remaining grouped by month ('cut'). This is a bad way to visualize the diamonds data, but should work well for buildings as their heating and cooling months typically don't overlap. So far I have:
p <- ggplot(data,
aes(color,value,group=cut))
p <- p + geom_bar(stat = 'identity',
position = 'dodge',
aes(fill = variable))
print(p)
I tried playing with scale_fill_manual, but couldn't think of a strategy that works:
colours <- c('#0000FF', '#0033FF', '#0066FF', '#FF0000', '#FF3300', '#FF6600')
p <- p + scale_fill_manual(values = colours,
group = data$variable)