plotrix Vs ggplot2: Pyramid plot visualization
Plotrix is one of the GNU R packages providing various plotting functions. This R package provides lots of labelling, plotting, axis and colour scaling functions.
I tried to analyze its functional capabilities and compare it with ggplot2 (another powerful data visualization package in R), and frankly, I feel that it's quite tough to pinpoint which is the best. Both have their own edges and downsides. Both have the potential to set universal plot settings and build customizable and complex plots from data in the data frame. An interesting thing to note is that while making a transition to another plot there is minimum adjustment and tweaking.
Below are some of my data visualization findings for pyramid plotting using plotrix and ggplot2.
Dataset info: Environmental indicators - Community and economy (Waikato): Waikato Regional Council releases the dataset which contains the environment and people's physical, economic, cultural and spiritual needs. Apart from the population info, it includes indicators about the relationships between people, the economy and the environment in the Waikato region and throughout New Zealand.
Dataset Source: Population structure
Using plotrix(pyramid plot as shown above):
Issues:
- the visualization looks a bit messier/unclear if it includes more than one or two years population data in the same plot
- scaling/labelling issue
Solution:
- for better clarity, I would rather recommend analyzing the plot for a specific year or (at the max three years) in the same plot. Remember, simple and high clarity is the best!
Using ggplot2 (pyramid plot as shown above):
Issues:
- complexity due to the use of aesthetics i.e. specifying x-, y-, colour, size
- requires more wrangling and structuring of data, for further analysis
- reading each bar value is difficult
Solution:
- use of gather or separate function accordingly
- use of scale_x_discrete/scale_y_continuous
Thanks for this post! Could you please include the code to produce these plots in the article or share it in a gist on GitHub? I'd like to play around with the ggplot2 version.