knitr::opts_chunk$set(fig.width = 6,
                      fig.height = 4,
                      fig.align='center',
                      dev = "png")

Introduction

The eechidna (Exploring Election and Census Highly Informative Data Nationally for Australia) R package makes it easy to look at the Census (and election) data from the 2001, 2006, 2011 and 2016 Australian Censuses.

This vignette documents how to access the Census data, using the example of 2016, and shows a few typical methods that can be used to explore the data.

2016 Census data

The data is loaded as abs2016 when you load eechidna.

library(eechidna)

data(abs2016)

Here we see that we have 150 observations and 86 variables.

Each observation is data pertaining to a particular federal electorate as described by http://www.aec.gov.au/profiles/.

Each variable is described here:

data_dictionary <- data.frame(
  Variable = names(abs2016), 
  Details = c(
    "Commonwealth Electoral District identifier",
    "Name of electorate",
    "State containing electorate",
    "Total population of electorate",
    "Area of electorate division in square kilometres",
    "Percentage of people aged 0-4.",
    "Percentage of people aged 5-9.",
    "Percentage of people aged 15-19.",
    "Percentage of people aged 20-24.",
    "Percentage of people aged 25-34.",
    "Percentage of people aged 35-44.",
    "Percentage of people aged 45-54.",
    "Percentage of people aged 55-64.",
    "Percentage of people aged 65-74.",
    "Percentage of people aged 75-84.",
    "Percentage of people aged 85 or higher.",
    "Percentage of people affiliated with the Anglican denomimation",
    "Percentage of people who are Australian Citizens",
    "Average number of people in a household",
    "Percentage of people who have completed a Bachelor degree or above",
    "Percentage of people born in Asia",
    "Percentage of people born in the Middle East",
    "Percentage of people born in South Eastern Europe",
    "Percentage of people born in the United Kingdom",
    "Percentage of people born in a different region outside of Australia",
    "Percentage of people who did not answer the question relating to birthplace",
    "Percentage of people affiliated with the Buddhist religion",
    "Percentage of people affiliated with the Catholic denomimation",
    "Percentage of people affiliated with the Christian religion (of all denominations)",
    "Percentage of households made up of a couple with no children",
    "Percentage of households made up of a couple with children",
    "Percentage of people who are currently studying",
    "Percentage of people who are in a de facto marriage",
    "Percentage of people who live at a different address to what they did 5 years ago",
    "Percentage of people who have completed a diploma or certificate (not including graduate diploma)",
    "Percentage of employed persons who work in wholesale trade, retail trade, transport, post or warehousing related industries",
    "Percentage of people who receive emuneration outside of Australia, out of the total population plus overseas visitors",
    "Percentage of people who speak only English",
    "Percentage of employed persons who work in extractive industries (includes mining, gas, water, agriculture, waste, electricity)",
    "Percentage of people who did not answer the question relating to family income",
    "Average number of people per family",
    "Percentage of employed persons who work in finance or insurance related industries",
    "Percentage of people who have completed high school",
    "Rate of nonresponse for questions relating to high school completion",
    "Percentage of people who did not answer the question relating to houshold income",
    "Percentage of people who are Indigenous",
    "Percentage of people with access to the internet",
    "Rate of nonresponse for questions relating to internal access",
    "Percentage of people who used interent in the last week [2001 only]",
    "Rate of nonresponse for questions relating to internet use [2001 only]",
    "Percentage of people affiliated with the Islamic religion",
    "Percentage of people affiliated with the Jewish religion",
    "Percentage of employed persons who work as a laborer",
    "Rate of nonresponse for questions relating to language spoken at home",
    "Labor force participation rate",
    "Percentage of employed persons who work in management, administration, clerical duties and sales",
    "Percentage of people who are married",
    "Median age",
    "Median weekly family income (in $)",
    "Median weekly household income (in $)",
    "Median mortgage loan repayment amount (of mortgage payments, in $)",
    "Median weekly personal income (in $)",
    "Median weekly rental payment amount (of those who rent, in $)",
    "Percentage of dwellings that are on a mortgage",
    "Percentage of people with no religion",
    "Percentage of households made up of one parent with children",
    "Percentage of people affiliated with a religion other than Christianity, Buddhism, Islam and Judaism",
    "Percentage of people affiliated with a denomination of the Christian religion other than Anglican or Catholic",
    "Percentage of people who speak a language other than English at home",
    "Percentage of dwellings that are owned outright",
    "Rate of nonresponse for questions relating to personal income",
    "Percentage of employed persons who work as a professional",
    "Percentage of dwellings that are owned by the government, and rented out to tenants",
    "Rate of nonresponse for questions relating to religion",
    "Rate of nonresponse for questions relating to rental costs",
    "Percentage of dwellings that are being rented",
    "Percentage of employed persons who work in education and training, healthcare, wocial work, community, arts and recreation",
    "Percentage of households occupied by a single person",
    "Rate of nonresponse for questions relating to tenure",
    "Percentage of employed persons who specialise in a trade",
    "Percentage of employed persons who work in construction or manufacturing related industries",
    "Unemployment rate",
    "Rate of nonresponse for questions relating to University",
    "Percentage of people who work as a volunteer",
    "Rate of nonresponse for questions relating to working as a volunteer")
    ) # close data_frame
library(knitr)
kable(data_dictionary)

So let's just look at some nice and simple plots using ggplot2.

Unemployment

library(ggplot2)
ggplot(data = abs2016,
       aes(x = Unemployed)) + 
  geom_density(fill = "salmon", 
               bw = "SJ",
               colour = NA) + 
  geom_rug(colour = "salmon") +
  theme_minimal() +
  xlim(0, 12)

Unemployment by state

ggplot(data = abs2016,
       aes(x = reorder(State, -Unemployed),
           y = Unemployed,
           colour = State)) + 
  geom_boxplot() + 
  labs(x = "State",
       y = "% Unemployment") + 
  theme_minimal() + 
  theme(legend.position = "none") 

Age

ggplot(data = abs2016,
       aes(x = Age00_04)) +
   geom_density(fill = "steelblue",
               bw = "SJ",
               colour = NA) + 
  xlim(3,11) +
  geom_rug(colour = "steelblue") + 
  theme_minimal() +
  labs(x = "% Aged between 0 and 4")
ggplot(data = abs2016,
       aes(x = reorder(State, -Age00_04),
           y = Age00_04,
           colour = State)) +
  geom_boxplot() + 
  theme_minimal() +
  labs(x = "State",
       y = "% Aged between 0 and 4") +
  theme(legend.position = "none") + 
  coord_flip()

However, there are many age groups. To look at all of them at once, we can gather them into a dataframe ready for plotting using tidyr.

library(tidyr)
library(dplyr)
abs2016 %>%
  select(starts_with("Age"), 
         DivisionNm) %>%
  gather(key = "Age",
         value = "Percent_in_electorate",
         -DivisionNm) %>% 
  ggplot(data = .,
         aes(x = reorder(Age, - Percent_in_electorate),
             y = Percent_in_electorate,
             colour = Age)) +
  geom_boxplot() + 
  coord_flip() + 
  theme_minimal() + 
  theme(legend.position = "none") +
  labs(x = "Age Groups",
       y = "% in Electorate")

Personal Income

ggplot(data = abs2016,
       aes(x = MedianPersonalIncome)) + 
  geom_density(fill = "salmon",
               bw = "SJ",
               colour = NA) + 
  xlim(250,1100) +
  geom_rug(colour = "salmon") + 
  theme_minimal()

Income by State

ggplot(data = abs2016,
       aes(x = reorder(State, -MedianPersonalIncome),
           y = MedianPersonalIncome,
           colour = State)) + 
  geom_boxplot() + 
  theme_minimal() + 
  theme(legend.position = "none") + 
  labs(x = "State")

If you're intersted in getting a sense of the distribution of the data, you can add in the points to get a bit more of a sense on the distribution.

ggplot(data = abs2016,
       aes(x = reorder(State, -MedianPersonalIncome),
           y = MedianPersonalIncome,
           colour = State)) + 
  geom_boxplot() + 
  geom_jitter(alpha = 0.35, 
              size = 2,
              width = 0.3) +
  theme_minimal() + 
  theme(legend.position = "none") + 
  labs(x = "State")

Education

Bachelor and above
ggplot(data = abs2016,
       aes(x = BachelorAbv)) +
  geom_density(fill = "salmon",
               bw = "SJ",
               colour = NA) + 
  geom_rug(colour = "salmon") + 
  theme_minimal() + 
  labs(x = "% of electorate with a Bachelor degree or above") +
  xlim(0, 55)
Bachelor by state
ggplot(data = abs2016,
       aes(x = reorder(State, -BachelorAbv),
           y = BachelorAbv,
           colour = State)) +
  geom_boxplot() +
  theme_minimal() +
  labs(x = "State") + 
  theme(legend.position = "none")
BachelorAbv and income
ggplot(data = abs2016,
       aes(x = BachelorAbv,
           y = MedianPersonalIncome)) + 
  geom_point(colour = "steelblue",
             alpha = 0.75) + 
  theme_minimal()

Diploma and Certificate

ggplot(data = abs2016,
       aes(x = reorder(State, -DipCert),
           y = DipCert,
           colour = State)) +
  geom_boxplot() +
  theme_minimal() +
  labs(x = "State") + 
  theme(legend.position = "none")
Diploma and Certificate and income
ggplot(data = abs2016,
       aes(x = DipCert,
           y = MedianPersonalIncome)) + 
  geom_point(colour = "steelblue",
             alpha = 0.75) + 
  theme_minimal()
Comparing income across Bachelor (and above) and Diploma/Certificate
abs2016 %>%
  select(DipCert,
         BachelorAbv,
         MedianPersonalIncome) %>% 
  gather(key = "Education",
         value = "Prop_Educated",
         -MedianPersonalIncome) %>%
ggplot(data = ,
       aes(x = Prop_Educated,
           y = MedianPersonalIncome,
           colour = Education)) + 
  geom_point() + 
  geom_smooth() +
  theme_minimal() +
  scale_color_brewer(type = "qual", palette = "Set1")

Religion

Let's look at all of the religions

abs2016 %>%
  select(Christianity,
         Catholic,
         Buddhism,
         Islam,
         Judaism,
         NoReligion) %>%
  gather(key = "ReligionType",
         value = "Percent") %>%
  ggplot(data = .,
         aes(x = reorder(ReligionType, -Percent),
             y = Percent,
             colour = ReligionType)) + 
  geom_boxplot() + 
  theme_minimal() + 
  theme(legend.position = "none") +
  coord_flip() + 
  labs(x = "Religion")
Christianity by State
ggplot(data = abs2016,
       aes(x = reorder(State, -Christianity),
           y = Christianity,
           colour = State)) + 
  geom_boxplot() +
  theme_minimal() +
  theme(legend.position = "none") +
  coord_flip() + 
  labs(x = "State")


ropenscilabs/eechidna documentation built on May 4, 2023, 6:51 a.m.