I am interested in focusing in on two factor variables in a facetted 35-panel gridded stacked bar chart plot - generating just a 10-panel plot.
The code for the original plot (which works) is as follows:
ggplot(region, aes(Year, Em_sum/1000000, fill=Region, order=Region)) +
geom_bar(position='fill', stat='identity') + scale_fill_brewer(palette="Set1") +
guides(fill = guide_legend(reverse=T)) + scale_y_continuous(labels = percent_format()) +
ylab("Proportion of Global FLW Emissions (%)") +
scale_x_discrete(breaks=seq(1961, 2011, 5)) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
facet_grid(Group ~ Stage, scales="free")
This code produces a 35-panel facetted stack bar chart grid. What I would like to do, in effect, is to show in the panel data from only two regions (instead of original seven), but keeping proportions of these two regions from the full data set. The result would be a 10 panel grid, 0-100%, but the two regions would not fill 100% of a facet, just the values of the two regions. The remaining 'white-space' in the panels in the combined proportion of the regions not included for that panel.
In implementing the solutions in the answer to what seemed a similar question (Subset and ggplot2) in the first line of my code as follows:
ggplot(subset(region, Region %in% c("NAm.Oceania", "Indus.Asia"), aes(Year, Em_sum/1000000, fill=Region, order=Region))) +
I get the following error:
Error in x[j] : invalid subscript type 'list'
Simplifying the code as follows (in line with the suggested solution above), produces a 100% stacked bar chart of just the two desired regions, but loses all the information from the other five regions. i.e. the plot is filled 100% rather than some lower value that is just the proportion of the two desire regions vs all seven.
ggplot(subset(region, Region %in% c("NAm.Oceania", "Indus.Asia"))) +
geom_bar(aes(Year, Em_sum/1000000, fill=Region, order=Region), position='fill', stat='identity')
My dataset is 232k rows - if an extract of that dataset would be useful, please suggest how I could provide it.
Thanks!