I have a dataframe from which I am producing a bar chart, the two columns I am using are:
TravelMode: Car/Van Car/Van Bus Train Bus Train Bicycle Car/Van Walk....
GovtRegion: North West South West London Scotland North West North West North East....
Each of these is a factor with 7 and 9 levels respectively. If I produce a tally() of these I can add a weight attribute so that my output percentages are "corrected":
tally(TravelMode ~ GovtRegion, data=qlfs_clean, margin='col', format='percent', weights='Weights', na.rm=TRUE)
However I cannot seem to get a ggplot stacked bar to work with this weighting. Is there any way I could add it so that the percentages in my bar chart are the weighted percentages and not the raw ones?
If I use weight="Weights" within the aes() attribute of ggplot it returns an empty chart:
ggplot(data=na.omit(qlfs_clean)) + geom_bar(aes(x=GovtRegion, fill=TravelMode, weight="Weights"),position="fill") + scale_y_continuous(labels = percent_format()) + ylab("") + xlab("Region") + facet_wrap(~AgeCat) + scale_fill_discrete(breaks=c("Car/Van","Motorcycle","Bicycle","Bus","Local Metro/Tram/Train","Walk","Other method")) + scale_fill_manual(values=cbPalette) + theme_bw() + theme(axis.text.x = element_text(angle = 90, hjust = 1))