Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
rsconnect
data/sql_export*
data/export*
data/enrolment*
data/enrolment*
.positai
7 changes: 5 additions & 2 deletions R/dashboard_panels.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ homepage_panel <- function() {
column(
12,
h1("Pupil attendance and absence in schools in England"),
textOutput("source_version_release")
div(
class = "govuk-body-s govuk-!-margin-bottom-4",
textOutput("source_version_release")
)
),

## Left panel -------------------------------------------------------
Expand Down Expand Up @@ -355,7 +358,7 @@ dashboard_panel <- function() {
fluidRow(
column(
width = 9,
girafeOutput("absence_reasons_timeseries")
plotOutput("absence_reasons_timeseries")
),
column(
width = 3,
Expand Down
10 changes: 5 additions & 5 deletions R/gov_colours.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# https://meyerweb.com/eric/tools/color-blend/#FFBF47:B10E1E:3:hex gov red to yellow

map_gov_colours <- c(
"#FFBF47",
"#EC933D",
"#D86733",
"#C53A28",
"#B10E1E"
"#fecc5c",
"#fd8d3c",
"#f03b20",
"#bd0026",
"#800026"
)

# Test the palette
Expand Down
2 changes: 1 addition & 1 deletion R/headline_panel.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ headline_panel <- function() {
bslib::card(
bslib::card_body(
uiOutput("headline_ts_chart_title"),
ggiraph::girafeOutput(
plotOutput(
"headline_absence_chart",
width = "100%",
height = "100%"
Expand Down
28 changes: 10 additions & 18 deletions R/line_formatters.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ headline_bullet <- function(
comparator_name <- paste(
"the",
region_la_lookup |>
filter(la_name == la_name_in) |>
pull(region_name)
dplyr::filter(la_name == la_name_in) |>
dplyr::pull(region_name)
) |>
stringr::str_replace("the London", "London")
} else if (geographic_level == "Regional") {
Expand All @@ -26,30 +26,22 @@ headline_bullet <- function(
area_string <- ""
comparator_level <- NULL
}

paste(
paste0(
value |>
as.numeric() |>
dfeR::round_five_up(dp = 1),
"%"
),
render_percents(value),
"of",
subject,
"were recorded as",
statistic_name,
area_string,
ifelse(
!is.null(comparator_level),
if (!is.null(comparator_level)) {
paste0(
"(compared to ",
comparator_value |>
as.numeric() |>
dfeR::round_five_up(dp = 1),
"% of sessions in ",
comparator_name,
")"
),
render_percents(comparator_value),
" of sessions in ", comparator_name, ")"
)
} else {
""
)
}
)
}
72 changes: 22 additions & 50 deletions R/plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ headline_absence_ggplot <- function(reasons, scope) {
date_breaks <- "1 day"
} else {
plot_data <- reasons |>
filter(
time_frame == "Week"
)
filter(time_frame == "Week")
date_breaks <- "1 month"
}

plot_data <- plot_data |>
filter(
attendance_reason %in%
Expand All @@ -27,8 +26,9 @@ headline_absence_ggplot <- function(reasons, scope) {
attendance_reason == "All unauthorised" ~ "Unauthorised absence rate"
)
)
dates <- plot_data |>
pull(reference_date)

dates <- plot_data |> pull(reference_date)

ggplot(
plot_data,
aes(
Expand All @@ -37,33 +37,19 @@ headline_absence_ggplot <- function(reasons, scope) {
colour = attendance_type
)
) +
geom_point_interactive(
aes(
tooltip = paste0(
date_stamp(lubridate::ymd(reference_date)),
"\n",
attendance_type,
": ",
session_percent,
"%"
)
)
) +
geom_line_interactive() +
geom_point() +
geom_line() +
scale_y_continuous(
limits = c(0, NA),
expand = expansion(mult = c(0, 0.2)), # This adds 20% of scale as white space
expand = expansion(mult = c(0, 0.2))
) +
scale_x_date(date_breaks = date_breaks, date_labels = "%d %b") +
afcharts::theme_af() +
scale_colour_manual(
values = afcharts::af_colour_palettes[["main6"]] |> unname()
) +
labs(
x = year(dates) |>
unique() |>
sort() |>
paste(collapse = "/"),
x = year(dates) |> unique() |> sort() |> paste(collapse = "/"),
y = "%",
colour = NULL
) +
Expand All @@ -84,11 +70,10 @@ reasons_ggplot <- function(reasons, scope) {
date_breaks <- "1 day"
} else {
plot_data <- reasons |>
filter(
time_frame == "Week"
)
filter(time_frame == "Week")
date_breaks <- "1 month"
}

plot_data <- plot_data |>
filter(
attendance_reason %in%
Expand All @@ -101,12 +86,10 @@ reasons_ggplot <- function(reasons, scope) {
)
) |>
arrange(attendance_type, reference_date) |>
mutate(
session_percent = as.numeric(session_percent)
)
mutate(session_percent = as.numeric(session_percent))

dates <- plot_data |> pull(reference_date)

dates <- plot_data |>
pull(reference_date)
ggplot(
plot_data,
aes(
Expand All @@ -115,22 +98,11 @@ reasons_ggplot <- function(reasons, scope) {
colour = attendance_reason
)
) +
geom_point_interactive(
aes(
tooltip = paste0(
date_stamp(lubridate::ymd(reference_date)),
"\n",
attendance_type,
": ",
session_percent,
"%"
)
)
) +
geom_line_interactive() +
geom_point() +
geom_line() +
scale_y_continuous(
limits = c(0, NA),
expand = expansion(mult = c(0, 0.2)), # This adds 20% of scale as white space
expand = expansion(mult = c(0, 0.2))
) +
scale_x_date(date_breaks = date_breaks, date_labels = "%d %b") +
afcharts::theme_af() +
Expand All @@ -140,13 +112,13 @@ reasons_ggplot <- function(reasons, scope) {
magrittr::extract(c(1, 2, 3, 4, 6))
) +
labs(
x = year(dates) |>
unique() |>
sort() |>
paste(collapse = "/"),
x = year(dates) |> unique() |> sort() |> paste(collapse = "/"),
y = "%",
colour = NULL
) +
theme(legend.position = "bottom", text = element_text(family = dfe_font)) +
theme(
legend.position = "bottom",
text = element_text(family = dfe_font)
) +
guides(color = guide_legend(nrow = 2, byrow = TRUE))
}
124 changes: 63 additions & 61 deletions R/prerun_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1965,67 +1965,69 @@ create_EES_daily_data <- function(attendance_data) {
) %>%
arrange(time_period, time_identifier, school_type) %>%
mutate(time_identifier = paste("Week", time_identifier, sep = " ")) %>%
mutate_at(
vars(
enrolments,
present_sessions,
overall_attendance,
approved_educational_activity,
overall_absence,
authorised_absence,
unauthorised_absence,
late_sessions,
possible_sessions,
reason_present_am,
reason_present_pm,
reason_present,
reason_l_present_late_before_registers_closed,
reason_i_authorised_illness,
reason_m_authorised_medical_dental,
reason_r_authorised_religious_observance,
reason_s_authorised_study_leave,
reason_t_authorised_mobile_child,
reason_h_authorised_holiday,
reason_e_authorised_excluded,
reason_c_authorised_other,
reason_c1_authorised_regulated_performance,
reason_j1_authorised_interview,
reason_c2_authorised_temp_reduced_timetable,
reason_b_aea_education_off_site,
reason_j_aea_interview,
reason_p_aea_approved_sporting_activity,
reason_v_aea_educational_visit_trip,
reason_w_aea_work_experience,
reason_k_aea_education_arranged_by_la,
reason_g_unauthorised_holiday,
reason_u_unauthorised_late_after_registers_closed,
reason_o_other_unauthorised,
reason_n_no_reason_yet,
total_num_schools,
total_enrolments,
attendance_perc,
overall_absence_perc,
authorised_absence_perc,
unauthorised_absence_perc,
illness_perc,
appointments_perc,
unauth_hol_perc,
unauth_oth_perc,
unauth_late_registers_closed_perc,
unauth_not_yet_perc,
auth_religious_perc,
auth_study_perc,
auth_mob_perc,
auth_excluded_perc,
auth_performance_perc,
auth_interview_perc,
auth_part_time_perc,
auth_other_perc
),
~ replace(
.,
geographic_level == "Local authority" & num_schools == 1,
"c"
mutate(
across(
c(
enrolments,
present_sessions,
overall_attendance,
approved_educational_activity,
overall_absence,
authorised_absence,
unauthorised_absence,
late_sessions,
possible_sessions,
reason_present_am,
reason_present_pm,
reason_present,
reason_l_present_late_before_registers_closed,
reason_i_authorised_illness,
reason_m_authorised_medical_dental,
reason_r_authorised_religious_observance,
reason_s_authorised_study_leave,
reason_t_authorised_mobile_child,
reason_h_authorised_holiday,
reason_e_authorised_excluded,
reason_c_authorised_other,
reason_c1_authorised_regulated_performance,
reason_j1_authorised_interview,
reason_c2_authorised_temp_reduced_timetable,
reason_b_aea_education_off_site,
reason_j_aea_interview,
reason_p_aea_approved_sporting_activity,
reason_v_aea_educational_visit_trip,
reason_w_aea_work_experience,
reason_k_aea_education_arranged_by_la,
reason_g_unauthorised_holiday,
reason_u_unauthorised_late_after_registers_closed,
reason_o_other_unauthorised,
reason_n_no_reason_yet,
total_num_schools,
total_enrolments,
attendance_perc,
overall_absence_perc,
authorised_absence_perc,
unauthorised_absence_perc,
illness_perc,
appointments_perc,
unauth_hol_perc,
unauth_oth_perc,
unauth_late_registers_closed_perc,
unauth_not_yet_perc,
auth_religious_perc,
auth_study_perc,
auth_mob_perc,
auth_excluded_perc,
auth_performance_perc,
auth_interview_perc,
auth_part_time_perc,
auth_other_perc
),
~ replace(
.x,
geographic_level == "Local authority" & num_schools == 1,
NA
)
)
)
}
Expand Down
11 changes: 3 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
render_percents <- function(values) {
dfeR::round_five_up(
as.numeric(
values
),
dp = 1
sprintf(
"%.2f%%",
dfeR::round_five_up(as.numeric(values), dp = 2)
) |>
paste0(
"%"
) |>
stringr::str_replace("NA%", "x")
}
Loading
Loading