Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated re-referall tables to show supression symbols #12

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
20 changes: 10 additions & 10 deletions R/plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -1424,10 +1424,10 @@ plot_cin_rates_la <- function(selected_geo_breakdown = NULL, selected_geo_lvl =
plot_cin_referral_reg <- function() {
referral_reg_data <- cin_referrals %>%
filter(geographic_level == "Regional", time_period == max(time_period)) %>%
select(time_period, geo_breakdown, Re_referrals_percent) %>%
mutate(geo_breakdown = reorder(geo_breakdown, -Re_referrals_percent)) # Order by turnover rate
select(time_period, geo_breakdown, Re_referrals_percentage) %>%
mutate(geo_breakdown = reorder(geo_breakdown, -Re_referrals_percentage)) # Order by turnover rate

ggplot(referral_reg_data, aes(`geo_breakdown`, `Re_referrals_percent`, fill = factor(time_period))) +
ggplot(referral_reg_data, aes(`geo_breakdown`, `Re_referrals_percentage`, fill = factor(time_period))) +
geom_col(position = position_dodge()) +
ylab("Re-referrals (%)") +
xlab("Region") +
Expand Down Expand Up @@ -1463,17 +1463,17 @@ plot_cin_referral_la <- function(selected_geo_breakdown = NULL, selected_geo_lvl
if (selected_geo_lvl == "Local authority") {
LA_referral_data <- cin_referrals %>%
filter(geographic_level == "Local authority", time_period == max(time_period)) %>%
select(time_period, geo_breakdown, Re_referrals_percent) %>%
select(time_period, geo_breakdown, Re_referrals_percentage) %>%
mutate(
geo_breakdown = reorder(geo_breakdown, -Re_referrals_percent), # Order by vacancy rate
geo_breakdown = reorder(geo_breakdown, -Re_referrals_percentage), # Order by vacancy rate
is_selected = ifelse(geo_breakdown == selected_geo_breakdown, "Selected", "Not Selected")
)
} else if (selected_geo_lvl == "National") {
LA_referral_data <- cin_referrals %>%
filter(geographic_level == "Local authority", time_period == max(time_period)) %>%
select(time_period, geo_breakdown, Re_referrals_percent) %>%
select(time_period, geo_breakdown, Re_referrals_percentage) %>%
mutate(
geo_breakdown = reorder(geo_breakdown, -Re_referrals_percent), # Order by vacancy rate
geo_breakdown = reorder(geo_breakdown, -Re_referrals_percentage), # Order by vacancy rate
is_selected = "Not Selected"
)
} else if (selected_geo_lvl == "Regional") {
Expand All @@ -1492,15 +1492,15 @@ plot_cin_referral_la <- function(selected_geo_breakdown = NULL, selected_geo_lvl

LA_referral_data <- cin_referrals %>%
filter(geo_breakdown %in% location, time_period == max(time_period)) %>%
select(time_period, geo_breakdown, Re_referrals_percent) %>%
select(time_period, geo_breakdown, Re_referrals_percentage) %>%
mutate(
geo_breakdown = reorder(geo_breakdown, -Re_referrals_percent), # Order by vacancy rate
geo_breakdown = reorder(geo_breakdown, -Re_referrals_percentage),
is_selected = "Selected"
)
}


p <- ggplot(LA_referral_data, aes(`geo_breakdown`, `Re_referrals_percent`, fill = `is_selected`)) +
p <- ggplot(LA_referral_data, aes(`geo_breakdown`, `Re_referrals_percentage`, fill = `is_selected`)) +
geom_col(position = position_dodge()) +
ylab("Re-referrals (%)") +
xlab("") +
Expand Down
28 changes: 15 additions & 13 deletions R/read_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -547,40 +547,42 @@ read_cin_referral_data <- function(file = "data/c1_children_in_need_referrals_an
geographic_level == "Regional" ~ region_name,
geographic_level == "Local authority" ~ la_name
)) %>%
mutate(Referrals = case_when(
mutate(Referrals_num = case_when(
Referrals == "Z" ~ NA,
Referrals == "x" ~ NA,
Referrals == "c" ~ NA,
TRUE ~ as.numeric(Referrals)
)) %>%
mutate(Re_referrals = case_when(
mutate(Re_referrals_num = case_when(
Re_referrals == "Z" ~ NA,
Re_referrals == "x" ~ NA,
Re_referrals == "c" ~ NA,
TRUE ~ as.numeric(Re_referrals)
)) %>%
mutate(Re_referrals_percent = case_when(
mutate(Re_referrals_percentage = case_when(
Re_referrals_percent == "Z" ~ NA,
Re_referrals_percent == "x" ~ NA,
Re_referrals_percent == "c" ~ NA,
TRUE ~ as.numeric(Re_referrals_percent)
)) %>%
select(time_period, geographic_level, geo_breakdown, region_code, region_name, new_la_code, la_name, Referrals, Re_referrals, Re_referrals_percent) %>%
select(
time_period, geographic_level, geo_breakdown, region_code, region_name, new_la_code, la_name,
Referrals, Re_referrals, Re_referrals_percent, Referrals_num, Re_referrals_num, Re_referrals_percentage
) %>%
distinct()


# Calculate the number of referrals not including re-referrals
referrals <- cin_referral_data %>%
group_by(time_period, geographic_level, geo_breakdown, region_code, region_name, new_la_code, la_name) %>%
summarise(
referrals_not_including_re_referrals_perc = round((Referrals - Re_referrals) / Referrals * 100, 1),
referrals_not_including_re_referrals = Referrals - Re_referrals,
.groups = "drop"
)
# referrals <- cin_referral_data %>%
# group_by(time_period, geographic_level, geo_breakdown, region_code, region_name, new_la_code, la_name) %>%
# summarise(
# referrals_not_including_re_referrals_perc = round((Referrals - Re_referrals) / Referrals * 100, 1),
# referrals_not_including_re_referrals = Referrals - Re_referrals,
# )

# Join the referall back to the original dataframe
cin_referral_data <- merge(referrals, cin_referral_data) %>%
arrange(desc(time_period))
# cin_referral_data <- merge(referrals, cin_referral_data) %>%
# arrange(desc(time_period))


return(cin_referral_data)
Expand Down
4 changes: 2 additions & 2 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ server <- function(input, output, session) {
stat <- "NA"
} else {
stat <- format(cin_referrals %>% filter(time_period == max(cin_referrals$time_period) & geo_breakdown %in% input$geographic_breakdown_o1)
%>% select(Re_referrals_percent), nsmall = 1)
%>% select(Re_referrals_percentage), nsmall = 1)
}

paste0(stat, "%", "<br>", "<p style='font-size:16px; font-weight:500;'>", "(", max(cin_referrals$time_period), ")", "</p>")
Expand Down Expand Up @@ -1671,7 +1671,7 @@ server <- function(input, output, session) {
}

ggplotly(
plotly_time_series_custom_scale(filtered_data, input$select_geography_o1, input$geographic_breakdown_o1, "Re_referrals_percent", "Re-referrals (%)", 100) %>%
plotly_time_series_custom_scale(filtered_data, input$select_geography_o1, input$geographic_breakdown_o1, "Re_referrals_percentage", "Re-referrals (%)", 100) %>%
config(displayModeBar = F),
height = 420
)
Expand Down
Loading