# Libraries use fot this work:
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(sf)
## Warning: package 'sf' was built under R version 4.2.3
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.2.1
library(dplyr)
library(ggplot2)
# Data Extract
censusdata <- unique(read.csv("DATA/ACT_census_data_by_sa1.csv"))
electorate <- unique(read.csv("DATA/sa1_electorate_correspondence.csv"))
mapping <- st_read("DATA/SA1_2021_AUST_SHP_GDA2020")
## Reading layer `SA1_2021_AUST_GDA2020' from data source
## `C:\Users\Julia\Desktop\Julia Romero - Canberra Profile\DATA\SA1_2021_AUST_SHP_GDA2020'
## using driver `ESRI Shapefile'
## Simple feature collection with 61845 features and 17 fields (with 34 geometries empty)
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 96.81695 ymin: -43.7405 xmax: 167.998 ymax: -9.142163
## Geodetic CRS: GDA2020
#* For the mapping: https://www.abs.gov.au/statistics/standards/australian-statistical-geography-standard-asgs-edition-3/jul2021-jun2026/access-and-downloads/digital-boundary-files
#str(censusdata)
#str(electorate)
#str(mapping)
# Data transformation
# JOINS
# Canberra filter
base1 <- censusdata %>%
left_join(electorate, by = "sa1_2021")
base1 <- base1 %>%
group_by(electorate) %>%
filter(electorate=="Canberra") %>%
filter(total >0)
# Geometry
head(mapping)
mapping <- mapping %>%
select(SA1_CODE21,SA2_NAME21,SA3_NAME21,geometry) %>%
mutate(SA1_CODE21 = as.numeric(SA1_CODE21))
## Warning: There was 1 warning in `stopifnot()`.
## ℹ In argument: `SA1_CODE21 = as.numeric(SA1_CODE21)`.
## Caused by warning:
## ! NAs introducidos por coerción
base1 <- base1 %>%
left_join(mapping, by = c("sa1_2021" = "SA1_CODE21"))
#str(base1)
base1_geo <- st_as_sf(base1)
Introduction
This work aims to provide an overview of the demographic characteristics of electorates in Canberra in 2021. The variables analyzed include under_18, age_18_29, age_30_49, age_over50, total, SA2_NAME21, SA3_NAME21, and electorate. For this analysis, data collected by the Australian Bureau of Statistics in the 2021 census was utilized. The units of study are distributed across Statistical Areas (SA1). Additionally, a dataset with geospatial data of the Statistical Area was used to obtain the necessary geometry information.
ggplot()+
geom_sf( data = base1_geo, aes( fill= total))+
scale_fill_gradient( low = "grey", high ="light blue")+
labs(title = "Population per Statistical Area",
fill = "Total population")+
theme_void()
# SA3 with more population:
summary1 <- aggregate(total ~ SA2_NAME21, data = base1_geo, FUN = sum)
# print(summary1)
ggplot(summary1, aes(x = reorder( SA2_NAME21, total) , y = total)) +
geom_bar(stat = "identity", fill = "blue") +
labs(x = "SA3", y = "People per SA3", title = "Bar Graph - Population per Suburbs") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
panel.grid = element_blank())
Populated Suburbs
The population map illustrates that the majority of the population of Canberra resides in the western part of the state. The graph “Population per Suburb” shows the distribution of people in each suburb of Canberra. Kaleen has the highest population registered in the Census 2021, with 6,610 people. Arboretum has the lowest population count.
Age distribution
In this analysis, the population was segmented into four groups: under 18, age between 18 and 29, age between 30 and 49 and age over 50. The population under 18 represents 18% of the total, those between 18 and 29 represent 22%, those between 30 and 49 represent 27%, and those over 50 represent 33%.
#Percentage calculation
#head(base1_geo)
Age_base1 <- base1_geo %>%
select(under_18, age_18_29, age_30_49, age_over50, total, SA2_NAME21, SA3_NAME21, electorate
) %>%
group_by(electorate) %>%
summarize(
total = sum(total),
under_18 = sum(under_18),
age_18_29 = sum(age_18_29),
age_30_49 = sum(age_30_49),
age_over50 = sum(age_over50))
Age_percentage <- Age_base1 %>%
mutate( percentage_under_18 = round((under_18 / total) * 100),
percentage_age_18_29 = round((age_18_29 / total) * 100),
percentage_age_30_49 = round((age_30_49 / total) * 100),
percentage_age_over50 = round((age_over50 / total) * 100)) %>%
select(percentage_under_18, percentage_age_18_29, percentage_age_30_49, percentage_age_over50)
#head(Age_percentage)
Age_plot_values <- Age_base1 %>%
pivot_longer(cols = c(under_18, age_18_29, age_30_49, age_over50),
names_to = "Age",
values_to = "Values")
ggplot(Age_plot_values, aes(x = reorder( Age, Values) , y = Values)) +
geom_col(stat = "identity", fill = "salmon", width = 0.6) +
labs(x = "SA3", y = "Age per population", title = "Bar Graph - Overal Age range") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 0, hjust = 1),
panel.grid = element_blank())
Age_base2 <- base1_geo %>%
select(under_18, age_18_29, age_30_49, age_over50, total, SA2_NAME21, SA3_NAME21, electorate
) %>%
group_by(SA3_NAME21) %>%
summarize(
total = sum(total),
under_18 = sum(under_18),
age_18_29 = sum(age_18_29),
age_30_49 = sum(age_30_49),
age_over50 = sum(age_over50))
Age_base2_pivot <- Age_base2 %>%
pivot_longer(cols = c(under_18, age_18_29, age_30_49, age_over50),
names_to = "Age",
values_to = "Values")
ggplot()+
geom_sf(data = Age_base2_pivot, aes(fill = Values))+
labs(title = "Age per Statistical Area",
fill = "Total population")+
theme_void()+
facet_wrap(facets = "Age",
nrow= 3)
Ancestry
Ancestry_base1 <- base1_geo %>%
select(australian_ancestry, chinese_ancestry, vietnamese_ancestry, indian_ancestry, filipino_ancestry, total, SA2_NAME21, SA3_NAME21, electorate) %>%
group_by(electorate) %>%
summarize(
total = sum(total),
australian = sum(australian_ancestry),
chinese = sum(chinese_ancestry),
vietnamese = sum(vietnamese_ancestry),
indian = sum(indian_ancestry),
filipino = sum(filipino_ancestry))
ancestry_percentage <- Ancestry_base1 %>%
mutate( australian = round((sum(australian)/total)*100),
chinese = round((sum(chinese)/total)*100),
vietnamese = round((sum(vietnamese)/total)*100),
indian = round((sum(indian)/total)*100),
filipino = round((sum(filipino)/total)*100))
ancestry_pivot <- ancestry_percentage %>%
pivot_longer(cols = c(australian, chinese, vietnamese, indian, filipino ),
names_to = "Ancestry",
values_to = "Percentages")
ggplot(ancestry_pivot, aes(x = Ancestry, y = Percentages)) +
geom_bar(stat = "identity", fill = "blue", width = 0.6) +
labs(x = "", y = "", title = "Bar Graph - Ancestry Identification") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
panel.grid = element_blank())
People_na <- 100 - sum(ancestry_percentage$australian + ancestry_percentage$chinese + ancestry_percentage$vietnamese + ancestry_percentage$indian + ancestry_percentage$filipino)
print(People_na)
## [1] 67
sum(ancestry_percentage$australian + ancestry_percentage$chinese + ancestry_percentage$vietnamese + ancestry_percentage$indian + ancestry_percentage$filipino)
## [1] 33
In the 2021 census, out of 122,290 censused people, only 33% provided information about their ancestry. Of those, 25% identified as Australian, 4% as Chinese, 1% as Vietnamese, 2% as Indian, and 1% as Filipino.
Conclusion
After analyzing the data, it can be concluded that the strongest segment of electorates is the population aged over 50 years who identify themselves as Australians.
Extra Dtabase source