NZ’s Shifting Makeup
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
New Zealand is culturally diverse. Even at a regional level, there are big differences in ethnic composition… and with an increasingly inter-connected world, ethnic composition is expected to change substantially in the future, particularly in Auckland.
Statistics New Zealand has provided us with sub-national ethnic population projections, by age and sex, from 2013 to 2038 which are well suited to visualisation using stacked area charts. The package ggplot2 in R makes generating these easy.
The following projections assume ‘medium fertility, medium paternity, medium mortality, medium net migration, and medium net inter-ethnic mobility.’ This is considered ‘medium growth’*.
Total New Zealand

Total North Island

Total South Island

Auckland

*Please see http://nzdotstat.stats.govt.nz for more information.
library(ggplot2) | |
library(dplyr) | |
# reading in the data | |
ethnic = read.csv(file = '...' | |
, stringsAsFactors = FALSE | |
, na = '') | |
ethnic_plot = function(areaOfInterest){ | |
# filtering on the area of interest | |
location = ethnic %>% filter(Area == areaOfInterest) | |
# plotting | |
ggplot(location | |
, aes(x = Year | |
, y = Proportion | |
, group = Ethnicity | |
, fill = Ethnicity)) + geom_area(position = 'fill', alpha = 0.6) + | |
scale_fill_manual(values=c('#ff0000', '#0000ff', '#009933', '#660066')) + | |
theme_bw(base_size = 15) + | |
scale_y_continuous(breaks=seq(0, 100, 0.1)) + | |
scale_x_continuous(breaks=seq(2013, 2038, 5)) | |
} |
References:
Data:
Subnational ethnic population projections, by age and sex, 2013(base)-2038. Statistics New Zealand. Provided under the creative commons attribution 3.0 New Zealand license.
I have transformed the data into proportions.
Plotting:
http://stackoverflow.com/questions/5030389/getting-a-stacked-area-plot-in-r
http://www.cookbook-r.com/Graphs/Axes_%28ggplot2%29/

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.