This is a template file. The example included is not considered a good example to follow for Assignment 2. Remove this warning prior to submitting.
Click the Original, Code and Reconstruction tabs to read about the issues and how they were fixed.
Objective
Explain the objective of the original data visualisation and the targetted audience.
The visualisation chosen had the following three main issues:
Reference
The following code was used to fix the issues identified in the original.
#Installation and calling of various required packages
library(readxl)
library(base)
library(ggplot2)
library(plyr)
library(dplyr)
library(tidyverse)
library(tidyr)
library(methods)
library(dplyr)
library(rgeos)
library(maptools)
library(ggmap)
library(broom)
library(graphics)
library(plotly)
library(leaflet)
library(forcats)
library(extrafont)
library(gridExtra)
library(htmlwidgets)
library(htmltools)
##Preparation of data sets
#Data import and scanning followed by data type conversions
#schoolsenrol <- read_excel("C:/Users/praam/OneDrive - RMIT University/schoolsenrol.xlsx", sheet = "LGA Data", skip = 9)
#Resaving the file by ensuring LGA names are same in .shp file
#write.xlsx(schoolsenrol, file = "schoolsenrol_use.xlsx")
#Data re import and removing unnecessary rows and columns
schoolsenrol_use <- read_excel("schoolsenrol_use.xlsx")
schools1 <- schoolsenrol_use[c(-81),]
#Adding proper column names to data set
colnames(schools1) <- c("LGA_name", "Gov_Schools_Enrols", "Gov_Schools_No.", "Catholic_Schools_Enrols", "Catholic_Schools_No.", "Indep_Schools_Enrols", "Indep_Schools_No.", "Total_Schools_Enrols", "Total_Schools_No.")
#Conversion of data types
schools1$"LGA_name" <- as.factor(schools1$"LGA_name")
schools1$"Gov_Schools_Enrols" <- as.numeric(schools1$"Gov_Schools_Enrols")
schools1$"Gov_Schools_No." <- as.numeric(schools1$"Gov_Schools_No.")
schools1$"Catholic_Schools_Enrols" <- as.numeric(schools1$"Catholic_Schools_Enrols")
schools1$"Catholic_Schools_No." <- as.numeric(schools1$"Catholic_Schools_No.")
schools1$"Indep_Schools_Enrols" <- as.numeric(schools1$"Indep_Schools_Enrols")
schools1$"Indep_Schools_No." <- as.numeric(schools1$"Indep_Schools_No.")
# identify NAs in full data frame and imputing them by 0
schools1[is.na(schools1)] <- 0
summary(schools1)
## LGA_name Gov_Schools_Enrols Gov_Schools_No. Catholic_Schools_Enrols
## ALPINE : 1 Min. : 20 Min. : 2.00 Min. : 0
## ARARAT : 1 1st Qu.: 1438 1st Qu.:10.00 1st Qu.: 314
## BALLARAT : 1 Median : 4702 Median :14.50 Median : 1824
## BANYULE : 1 Mean : 8068 Mean :19.46 Mean : 2642
## BASS COAST: 1 3rd Qu.:12534 3rd Qu.:28.00 3rd Qu.: 4077
## BAW BAW : 1 Max. :46216 Max. :64.00 Max. :11587
## (Other) :74
## Catholic_Schools_No. Indep_Schools_Enrols Indep_Schools_No.
## Min. : 0.000 Min. : 0.00 Min. : 0.000
## 1st Qu.: 2.000 1st Qu.: 72.75 1st Qu.: 1.000
## Median : 5.000 Median : 868.00 Median : 2.000
## Mean : 6.225 Mean : 1984.01 Mean : 2.888
## 3rd Qu.: 9.000 3rd Qu.: 3186.50 3rd Qu.: 4.000
## Max. :21.000 Max. :13465.20 Max. :18.000
##
## Total_Schools_Enrols Total_Schools_No.
## Min. : 20 Min. : 2.00
## 1st Qu.: 2071 1st Qu.:13.00
## Median : 8573 Median :23.50
## Mean :12694 Mean :28.57
## 3rd Qu.:20283 3rd Qu.:42.00
## Max. :63454 Max. :88.00
##
# Adding columns after another column for ratio ie. to calculate No. of students per school
school_ratio <- schools1 %>% add_column(Gov_Schools_Ratio = (schools1$Gov_Schools_Enrols/ schools1$Gov_Schools_No.),.after = "Gov_Schools_No.")
school_ratio1 <- school_ratio %>% add_column(Catholic_Schools_Ratio = (school_ratio$Catholic_Schools_Enrols/ school_ratio$Catholic_Schools_No.),.after = "Catholic_Schools_No.")
school_ratio2 <- school_ratio1 %>% add_column(Indep_Schools_Ratio = (school_ratio1$Indep_Schools_Enrols/ school_ratio1$Indep_Schools_No.),.after = "Indep_Schools_No.")
school_ratio3 <- school_ratio2 %>% add_column(Total_Schools_Ratio = (school_ratio2$Total_Schools_Enrols/ school_ratio2$Total_Schools_No.),.after = "Total_Schools_No.")
# identify NAs in full data frame and imputing them by 0
school_ratio3[is.na(school_ratio3)] <- 0
#Ranking the LGA's as per descending order of Total_Number of schools per Victoria LGA
school_ratio_rank <- school_ratio3 %>% add_column(Total_Schools_No._Rank = rank(desc(school_ratio3$Total_Schools_No.),ties.method = "min"),.before = "LGA_name")
###Conversion of Rank variable data type
###school_ratio_rank$Total_Schools_No._Rank <- as.factor(school_ratio_rank2$Total_Schools_No._Rank)
#Reordering of columns for likewise categories
school_ratio_rank2 <- school_ratio_rank[, c(1,2,13,4,7,10,12,3,6,9,14,5,8,11)]
#Subsetting dataset
school_ratio_rank3 <- school_ratio_rank2[, c(1,2,4,5,6)]
#school_ratio_rank3_long <- gather(school_ratio_rank3, key = "Variable", value = "Value", All_Schools_Ratio:Independent_Schools_Ratio)
school_ratio_rank3_long <- gather(school_ratio_rank3, key = "Variable", value = "School_Nos", Gov_Schools_No.:Indep_Schools_No.)
#Conversion of data type
school_ratio_rank3_long$Variable <- as.factor(school_ratio_rank3_long$Variable)
#Plotting bar plots for each category type school numbers in descending order of Total number of schools per LGA
schoolsum_Gov <- sum(school_ratio_rank2$Gov_Schools_No.)
schoolsum_Catholic <- sum(school_ratio_rank2$Catholic_Schools_No.)
schoolsum_Indep <- sum(school_ratio_rank2$Indep_Schools_No.)
schoolsum_df <- data.frame (schoolsum_Gov,schoolsum_Catholic, schoolsum_Indep)
# add column names
colnames(schoolsum_df) <- c("Total_Gov_Schools_No.", "Total_Catholic_Schools_No.", "Total_Indep_Schools_No.")
schoolsum_df_long <- gather(schoolsum_df, key = "Variable", value = "School_Nos", Total_Gov_Schools_No.:Total_Indep_Schools_No.)
#Plotting bar plots for each category type total number of schools - 2022
p1 <- plot_ly(data = schoolsum_df_long, x = ~Variable, y = ~School_Nos, color = ~Variable, type = "bar",
colors = c("Dark2")) %>%
#colors = c("#67a9cf","#ef8a62","#566638")) %>%
layout(yaxis = list(zeroline = FALSE, title = "Total School Numbers"),
xaxis = list(zeroline = FALSE, title = "School Category Type")) %>%
layout(title ="Total nos. of Victoria schools (categoriwise) - 2022", xaxis = list(categoryorder = "array",
categoryarray = c("Total_Gov_Schools_No.", "Total_Catholic_Schools_No.", "Total_Indep_Schools_No.")))
#Plotting bar plots for each category type school FTE students enrolments per LGA
studentsum_Gov <- sum(school_ratio_rank2$Gov_Schools_Enrols)
studentsum_Catholic <- sum(school_ratio_rank2$Catholic_Schools_Enrols)
studentsum_Indep <- sum(school_ratio_rank2$Indep_Schools_Enrols)
studentsum_df <- data.frame (studentsum_Gov,studentsum_Catholic, studentsum_Indep)
# add column names
colnames(studentsum_df) <- c("Total_Gov_Schools_Enrols", "Total_Catholic_Schools_Enrols", "Total_Indep_Schools_Enrols")
studentsum_df_long <- gather(studentsum_df, key = "Variable", value = "Student_Nos", Total_Gov_Schools_Enrols:Total_Indep_Schools_Enrols)
p2 <- plot_ly(data = studentsum_df_long, x = ~Variable, y = ~Student_Nos, color = ~Variable, type = "bar",
colors = c("Dark2")) %>%
#colors = c("#67a9cf","#ef8a62","#566638")) %>%
layout(yaxis = list(zeroline = FALSE, title = "Total FTE student Nos."),
xaxis = list(zeroline = FALSE, title = "School Category Type")) %>%
layout(title ="Full Time Enrolled (FTE) students in Victoria schools (categoriwise) - 2022", xaxis = list(categoryorder = "array", categoryarray = c("Total_Gov_Schools_Enrols", "Total_Catholic_Schools_Enrols", "Total_Indep_Schools_Enrols")))
#school_ratio_rank3_long$Rank_labels <- c(rank(-school_ratio_rank3$All_Schools_Ratio,ties.method = "min"),
#rank(-school_ratio_rank3$Government_Schools_Ratio,ties.method = "min"), #rank(-school_ratio_rank3$Catholic_Schools_Ratio,ties.method = "min"),
#rank(-school_ratio_rank3$Independent_Schools_Ratio,ties.method = "min"))
school_ratio_rank3_long$Rank_labels <- c(rank(-school_ratio_rank3$Gov_Schools_No.,ties.method = "min"), rank(-school_ratio_rank3$Catholic_Schools_No.,ties.method = "min"),
rank(-school_ratio_rank3$Indep_Schools_No.,ties.method = "min"))
#school_ratio_rank3_long$Variable <- factor(school_ratio_rank3_long$Variable,
# levels = c("All_Schools_Ratio","Government_Schools_Ratio","Catholic_Schools_Ratio", "Independent_Schools_Ratio"),
# labels = c("All Schools types",
# "Government Schools",
# "Catholic Schools", "Independent Schools"))
school_ratio_rank3_long$Variable <- factor(school_ratio_rank3_long$Variable,
levels = c("Gov_Schools_No.","Catholic_Schools_No.", "Indep_Schools_No."),
labels = c("Government Schools","Catholic Schools", "Independent Schools"))
school_ratio_rank3_long1 <- arrange(school_ratio_rank3_long,Total_Schools_No._Rank)
#Plotting bar plots for each category type school numbers in descending order of Total number of schools per LGA
p3 <- ggplot(data = school_ratio_rank3_long1,
aes(x = LGA_name, y = School_Nos, fill = Variable)) + geom_bar(stat = "identity") + scale_fill_manual(values = c("#D95F02","#1B9E77","#7570B3")) + theme_minimal() + coord_flip() + facet_grid(.~Variable, scales = "free") + theme(legend.position="none") + theme(axis.text = element_text(size = 3,face = "bold"))
#p1 <- ggplot(data = school_ratio_rank3_long,
# aes(x = LGA_name, y = School_Nos, fill = Variable)) + geom_bar(stat = "identity") + scale_fill_manual(values = #c("#1569C7","#94703D","#566638")) + theme_minimal()+coord_flip() +
# facet_grid(.~Variable, scales = "free")+theme(legend.position="none")+ theme(axis.text = element_text(size = 3,face = "bold"))
p4 <- p3 +
geom_text(aes(label = Rank_labels, y = 0),
fill = "gray", hjust = "top", size= 1.2,face = "bold", family="Arial")
p5 <- p4 + labs(title = "Categoriwise distribution of Total Victoria schools for each LGA - 2022",
subtitle = "Local Governing Area (LGA) arranged in descending order of Total no. of schools",
caption = "Source: State of Victoria (Department of Education and Training) 2022
*https://www.vic.gov.au/statistics-victorian-schools-and-teaching")
background <- "#EFF1F0"
#Plot to visualize Total number of schools for each Victoria LGA - 2022
p6 <- p5 +
theme_gray() +
theme(legend.position="none", axis.text.x = element_text(size = 10,face = "bold"),axis.text.y = element_text(size = 3,face = "bold"), plot.background = element_rect(fill = background),
panel.background = element_rect(fill = background),legend.background = element_rect(fill = background),title = element_text(face = "bold"),legend.title = element_blank(),axis.title.x = element_blank(),
axis.title.y = element_blank())
p6
#Plot to visualize Total number of schools for each Victoria LGA - 2022 with added interaction using plotly to show numbers and rank on cursor movement
p7 <- ggplotly(p6, width = 800, height = 490)
p7
#Creating visualization for the Ratio ie. No. of FTE students enrolled per school by LGA - 2022
#Subsetting dataset
school_ratio_rank4 <- school_ratio_rank2[, c(1,2,11,12,13,14)]
#school_ratio_rank3_long <- gather(school_ratio_rank3, key = "Variable", value = "Value", All_Schools_Ratio:Independent_Schools_Ratio)
school_ratio_rank4_long <- gather(school_ratio_rank4, key = "Variable", value = "Students_Ratio", Total_Schools_Ratio:Indep_Schools_Ratio)
#Conversion of data type
school_ratio_rank4_long$Variable <- as.factor(school_ratio_rank4_long$Variable)
school_ratio_rank4_long$Rank_labels <- c(rank(-school_ratio_rank4$Total_Schools_Ratio,ties.method = "min"),
rank(-school_ratio_rank4$Gov_Schools_Ratio,ties.method = "min"), rank(-school_ratio_rank4$Catholic_Schools_Ratio,ties.method = "min"),
rank(-school_ratio_rank4$Indep_Schools_Ratio,ties.method = "min"))
#school_ratio_rank3_long$Variable <- factor(school_ratio_rank3_long$Variable,
# levels = c("All_Schools_Ratio","Government_Schools_Ratio","Catholic_Schools_Ratio", "Independent_Schools_Ratio"),
# labels = c("All Schools types",
# "Government Schools",
# "Catholic Schools", "Independent Schools"))
school_ratio_rank4_long$Variable <- factor(school_ratio_rank4_long$Variable,
levels = c("Total_Schools_Ratio","Gov_Schools_Ratio","Catholic_Schools_Ratio", "Indep_Schools_Ratio"),
labels = c("Average of Total Schools","Government Schools","Catholic Schools", "Independent Schools"))
school_ratio_rank4_long1 <- arrange(school_ratio_rank4_long,Total_Schools_No._Rank)
#Plotting bar plots for each category type school numbers
#p8 <- plot_ly(data = school_ratio_rank7_long, x = ~LGA_name, y = ~Students_ratio, type = "bar", color = ~Variable,
#colors = c("#67a9cf","#ef8a62","#67a9cf","#ef8a62")) %>%
#layout(yaxis = list(zeroline = FALSE, title = "Student ratio"),
# xaxis = list(zeroline = FALSE, title = "LGA Name"))
#p8
#Plotting the scatter plot with ratio as y axis
#p9 <- plot_ly(data = school_ratio_rank4_long, x = ~LGA_name, y = ~Students_Ratio,
#size = ~Students_Ratio , alpha = 2, symbol = ~Variable, color = ~Variable, type = "scatter", mode = "markers",
#colors = "Dark2") %>%
#layout(title = "Ratio ie. number of FTE Students per school, categoriwise, by LGA - 2022",
#yaxis = list(zeroline = FALSE, title = "No. of FTE Students (ratio) per school"),
#xaxis = list(zeroline = FALSE, title = "Victoria LGA"))
#p9
#Plotting the scatter plot with student ratio as x axis for better visualization with axis scales like Victoria LGA No. of schools
p8 <- plot_ly(data = school_ratio_rank4_long, x = ~Students_Ratio, y= ~LGA_name,
size = ~Students_Ratio , alpha = 2, symbol = ~Variable, color = ~Variable, type = "scatter", mode = "markers",
colors = c("#E7298A","#D95F02","#1B9E77","#7570B3")) %>%
layout(title ="Students enrolments per school (categorical), Victoria LGA - 2022",
xaxis = list(zeroline = FALSE, title = "Ratio (No. of FTE Students per school)"),
yaxis = list(zeroline = FALSE, title = "Victoria LGA"))
p8
##LGA map of All Victoria schools - 2022
vic.lga.shp <- readShapeSpatial("C:/Users/praam/OneDrive - RMIT University/vmlite_lga_cm/vmlite_lga_cm.shp")
class(vic.lga.shp)
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
names(vic.lga.shp)
## [1] "ufi" "ftype_code" "lga_name" "state" "scale_usec"
## [6] "labeluse_c" "ufi_cr" "lga_name3" "cartodb_id" "created_at"
## [11] "updated_at"
head(vic.lga.shp$lga_name)
## [1] SWAN HILL TOWONG
## [3] MOUNT BAW BAW ALPINE RESORT SOUTH GIPPSLAND
## [5] SOUTHERN GRAMPIANS WELLINGTON
## 87 Levels: ALPINE ARARAT BALLARAT BANYULE BASS COAST BAW BAW ... YARRIAMBIACK
#Checking and ensuring LGA names to be same
head(schools1$LGA_name)
## [1] ALPINE ARARAT BALLARAT BANYULE BASS COAST BAW BAW
## 80 Levels: ALPINE ARARAT BALLARAT BANYULE BASS COAST BAW BAW ... YARRIAMBIACK
colnames(schools1)[1] <- "lga_name"
lga.shp.f <- tidy(vic.lga.shp, region = "lga_name")
head(lga.shp.f)
## # A tibble: 6 × 7
## long lat order hole piece group id
## <dbl> <dbl> <int> <lgl> <fct> <fct> <chr>
## 1 147. -36.4 1 FALSE 1 ALPINE.1 ALPINE
## 2 147. -36.4 2 FALSE 1 ALPINE.1 ALPINE
## 3 147. -36.5 3 FALSE 1 ALPINE.1 ALPINE
## 4 147. -36.5 4 FALSE 1 ALPINE.1 ALPINE
## 5 147. -36.5 5 FALSE 1 ALPINE.1 ALPINE
## 6 147. -36.5 6 FALSE 1 ALPINE.1 ALPINE
lga.shp.f$lga_name <-lga.shp.f$id
head(lga.shp.f)
## # A tibble: 6 × 8
## long lat order hole piece group id lga_name
## <dbl> <dbl> <int> <lgl> <fct> <fct> <chr> <chr>
## 1 147. -36.4 1 FALSE 1 ALPINE.1 ALPINE ALPINE
## 2 147. -36.4 2 FALSE 1 ALPINE.1 ALPINE ALPINE
## 3 147. -36.5 3 FALSE 1 ALPINE.1 ALPINE ALPINE
## 4 147. -36.5 4 FALSE 1 ALPINE.1 ALPINE ALPINE
## 5 147. -36.5 5 FALSE 1 ALPINE.1 ALPINE ALPINE
## 6 147. -36.5 6 FALSE 1 ALPINE.1 ALPINE ALPINE
merge.lga.profiles<-merge(lga.shp.f, schools1,
by="lga_name", all.x=TRUE)
choro.data.frame<-merge.lga.profiles[order(merge.lga.profiles$order), ]
class(vic.lga.shp)
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
p9 <- leaflet(vic.lga.shp) %>%
setView(lng = 145.5, lat = -36.5, zoom = 6)
p9 %>% addPolygons()
#Merge dataset files by lga_name
merge.lga.profiles3<-sp::merge(vic.lga.shp, schools1, by="lga_name", duplicateGeoms = TRUE)
bins <- quantile(
schools1$Total_Schools_No.,
probs = seq(0,1,.2), names = FALSE, na.rm = TRUE)
bins
## [1] 2.0 12.8 18.0 29.8 44.0 88.0
#Colour coding by bins
pal <- colorBin(
"YlOrRd",
domain = schools1$Total_Schools_No.,
bins = bins
)
p10 <- leaflet(merge.lga.profiles3) %>%
setView(lng = 147, lat = -36.5, zoom = 6)
p10 %>% addPolygons(
fillColor = ~pal(Total_Schools_No.),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7)
p10 %>% addPolygons(
fillColor = ~pal(Total_Schools_No.),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 3,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE))
labels <- sprintf(
"<strong>%s</strong><br/>%g Total No.of Schools",
merge.lga.profiles3$lga_name,
merge.lga.profiles3$Total_Schools_No.
) %>% lapply(htmltools::HTML)
p10 %>% addPolygons(
fillColor = ~pal(Total_Schools_No.),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto"))
labels <- sprintf(
"<strong>%s</strong><br/>%g Total No.of Schools",
merge.lga.profiles3$lga_name,
merge.lga.profiles3$Total_Schools_No.
) %>% lapply(htmltools::HTML)
#Title and legends to plot
title <- tags$div(
HTML('<h3>Victoria Total Nos. of Schools by LGA - 2022</h3>')
)
p10 %>% addPolygons(
fillColor = ~pal(Total_Schools_No.),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal,
values = ~Total_Schools_No.,
opacity = 0.7, title = "Total No.of Schools",
position = "bottomright") %>%
addControl(title, position = "topright")
#Continuous color scale
pal3 <- colorNumeric(
"YlOrRd",
domain = schools1$Total_Schools_No.,
)
p10 %>% addPolygons(
fillColor = ~pal3(Total_Schools_No.),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal3,
values = ~Total_Schools_No.,
opacity = 0.7, title = "Total No.of Schools",
position = "bottomright") %>%
addControl(title, position = "topright")
##LGA map of Total no. of FTE Student enrolment nos.
p11 <- leaflet(vic.lga.shp) %>%
setView(lng = 145.5, lat = -36.5, zoom = 6)
p11 %>% addPolygons()
#Merge dataset files by lga_name
merge.lga.profiles33<-sp::merge(vic.lga.shp, schools1, by="lga_name", duplicateGeoms = TRUE)
bins <- quantile(
schools1$Total_Schools_Enrols,
probs = seq(0,1,.2), names = FALSE, na.rm = TRUE)
bins
## [1] 20.00 1681.66 5095.62 11143.68 22128.04 63453.70
#Colour coding by bins
pal <- colorBin(
"Greens",
domain = schools1$Total_Schools_Enrols,
bins = bins
)
p12 <- leaflet(merge.lga.profiles33) %>%
setView(lng = 147, lat = -36.5, zoom = 6)
p12 %>% addPolygons(
fillColor = ~pal(Total_Schools_Enrols),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7)
p12 %>% addPolygons(
fillColor = ~pal(Total_Schools_Enrols),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 3,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE))
labels <- sprintf(
"<strong>%s</strong><br/>%g Total No. of FTE Student Enrolemnts",
merge.lga.profiles33$lga_name,
merge.lga.profiles33$Total_Schools_Enrols
) %>% lapply(htmltools::HTML)
p12 %>% addPolygons(
fillColor = ~pal(Total_Schools_Enrols),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto"))
labels <- sprintf(
"<strong>%s</strong><br/>%g Total No.of FTE Student Enrolemnts",
merge.lga.profiles33$lga_name,
merge.lga.profiles33$Total_Schools_Enrols
) %>% lapply(htmltools::HTML)
#Title and legends to plot
title <- tags$div(
HTML('<h3>Victorian Total No.of FTE Students enrolment in Schools by LGA - 2022</h3>')
)
p12 %>% addPolygons(
fillColor = ~pal(Total_Schools_Enrols),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal,
values = ~Total_Schools_Enrols,
opacity = 0.7, title = "Total No.of FTE Student Enrolemnts",
position = "bottomright") %>%
addControl(title, position = "topright")
#Continuous color scale
pal9 <- colorNumeric(
"Greens",
domain = schools1$Total_Schools_Enrols,
)
p12 %>% addPolygons(
fillColor = ~pal9(Total_Schools_Enrols),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal9,
values = ~Total_Schools_Enrols,
opacity = 0.7, title = "Total No. of FTE Student Enrolemnts",
position = "bottomright") %>%
addControl(title, position = "topright")
Data Reference
The following plot fixes the main issues in the original.
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.