Similar questions have been asked before (e.g., one; two), however, the answers seem to be missing the point; also, my question is slightly different. Here is the base plot:
And this is the code that created it:
p1 <- ggplot(data=a2.st, aes(x=Type, y=lFreq, fill=factor(Hit))) +
geom_bar(position='stack', stat='identity', width=0.5) +
scale_x_discrete(name='Type',
breaks=breaks, labels=labels) +
scale_y_continuous('Frequency', limits=c(0, 240)) +
scale_fill_manual(values=c('#d95f02','#1b9e77'), name='Hit:',
breaks=c('0','1'),
labels=c('yes','no')) +
theme(plot.title=element_text(hjust=0.5),
axis.text.x=element_text(size=10, angle=45, vjust=1, hjust=1),
axis.text.y=element_text(size=11),
axis.title=element_text(size=12),
legend.text=element_text(size=10))
p1
Instead of one stacked bar for a level of Type, is there a way to add three more bars such that Type differentiates between four levels of another variable? In other words, each Type would group four levels of variable Level.
