The dataset examined contains the religious beliefs of all Australians in 2016 segmented into various age groups.
Prior to importing the excel sheet, the sheet was modified to combine Judaism with the Other religions as Judaism numbers are too small to have their own category.
Non-religious are defined as beliefs such as athiesm, agnosticism and secular beliefs.
The portion of Australians that did not state or did not adequately describe their religion will be excluded from analysis.
Buddhism, Christianity, Islam, Hinduism, Non-Religious will be the main beliefs of focus in the visualisation with all other religions falling under the catergory of other.
The age groups will also be set at 15 year intervals instead of the intervals set in the original dataset for easier viewing.
From the dataset, we will be trying to determine if there is a noticeable trend in the splits of religious beliefs across varying age groups as well as looking at the general split of religions in all of Australia.
# Load packages
library(readxl)
## Warning: package 'readxl' was built under R version 3.5.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.3
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.5.3
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(cowplot)
## Warning: package 'cowplot' was built under R version 3.5.3
##
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggplot2':
##
## ggsave
library(RColorBrewer)
## Data
religion <- read_excel("207104 - Religion.xls", sheet = 3,col_names = TRUE, range = "A7:T187")
## New names:
## * `` -> `..1`
# Selecting the rows with the specific religions we wish to visualise.
r1 <- data.frame(religion[c(112,177,115,1,114,157),])
#Creating new column named Religion
r1$Religion <- c("Christianity", "Non-Religious", "Islam", "Buddhism", "Hinduism", "Other")
#Adding columns to display wider age ranges
r1$'0 to 14' <- r1$X0.4.years + r1$X5.9.years + r1$X10.14.years
r1$'15 to 29' <- r1$X15.19.years + r1$X20.24.years + r1$X25.29.years
r1$'30 to 44' <- r1$X30.34.years + r1$X35.39.years + r1$X40.44.years
r1$'45 to 59' <- r1$X45.49.years + r1$X50.54.years + r1$X55.59.years
r1$'60 to 74' <- r1$X60.64.years + r1$X65.69.years + r1$X70.74.years
r1$'75 to 85+' <- r1$X75.79.years + r1$X80.84.years + r1$X85.
r1$TotalCount <- r1$Total
#Creating a new dataframe using the new columns
r2 <- r1[, c(21:28)]
#Gathering columns and converting the dataframe to long format
r3 <- r2 %>% gather('Age_Group','Persons', c(2:8))
#Create new dataset containing total figures
TotalReligion <- r3[37:42,c(1,3)]
TotalReligion$Percentage <- (TotalReligion$Persons/sum(TotalReligion$Persons))
#Create new dataset containing age split of religions
AgeProp <- xtabs(Persons ~ Religion + Age_Group, r3[1:36,])
AgeProp2 <- AgeProp %>% prop.table(margin = 2) %>% data.frame()
#Reordering by Religion
TotalReligion$Religion <- factor(TotalReligion$Religion, levels = c("Christianity", "Non-Religious", "Islam", "Buddhism", "Hinduism", "Other"), ordered = TRUE)
AgeProp2$Religion <- factor(AgeProp2$Religion, levels = c("Christianity", "Non-Religious", "Islam", "Buddhism", "Hinduism", "Other"), ordered = TRUE)
#Creating first plot object showing total relgion split in Australia 2016
p1 <- ggplot(data = TotalReligion, aes(x = Religion, y = Percentage))
p1 + geom_bar(stat = "identity", fill ="skyblue", position = "dodge", color = "black") + labs(title = "Top 6 Religious Beliefs in Australia 2016", x = "Religious Beliefs", y = "Percentage of Australians") + theme_bw() + scale_y_continuous(labels = scales::percent_format(), limits = c(0,1), expand = c(0,0)) + geom_text(aes(label=round((Percentage*100),2)), vjust = -0.5) + theme(plot.title = element_text(hjust = 0.5))
#Creating second plot object showing religion split by age groups in Australia 2016
p2 <- ggplot(data = AgeProp2, aes(x = Age_Group, y = Freq, fill = Religion))
p2 + geom_bar(stat = "identity", aes(fill = Religion), position = "dodge", color = "black") + labs(title = "Top 6 Religious Beliefs in Australia 2016 by Age Groups", x = "Age Groups", y = "Percentage of Age Groups") + theme_bw() + theme(plot.title = element_text(hjust = 0.5)) + scale_y_continuous(labels = scales::percent_format(), limits = c(0,1), expand = c(0,0)) + facet_grid(. ~ Age_Group, scales = "free") + theme(strip.background = element_rect(colour="black", fill="skyblue",linetype="solid"), axis.text.x=element_blank())