Questions to answer
Loading the libraries
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 1.0.1
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(scales)
##
## Attaching package: 'scales'
##
## The following object is masked from 'package:purrr':
##
## discard
##
## The following object is masked from 'package:readr':
##
## col_factor
library(DT)
Importing the cleaned data
sped <- read_rds("data-processed/01-sped.rds")
sped %>% head()
Pivoting wider so that each year is its own column
district_percents_data <- sped |>
select(distname, cntyname, year, sped_percent) |>
pivot_wider(names_from = year, values_from = sped_percent)
district_percents_data |>
datatable()
Has the percentage of special education students in Texas changed since the benchmarking policy was dropped?
yearly_percent <- sped |>
group_by(year) |>
summarise(
total_students = sum(all_count),
total_sped = sum(sped_count)
) |>
mutate(sped_percent = ((total_sped / total_students) * 100) |> round(1))
yearly_percent
yearly_percent |>
ggplot(aes(x = year, y = sped_percent)) +
geom_col() +
geom_text(aes(label = sped_percent, vjust = -.5))
How many districts were above that arbitrary 8.5% benchmark before and after the changes?
flag_count_districts <- sped %>%
group_by(year, audit_flag) %>%
summarize("count_districts" = n())
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
flag_count_districts
Building the first exploratory chart
flag_count_districts |>
ggplot(aes(x = year, y = count_districts, fill = audit_flag)) +
geom_col()
Building the grouped column version
flag_count_districts |>
ggplot(aes(x = year, y = count_districts, fill = audit_flag)) +
geom_col(position = "dodge")
Building the line chart
flag_count_districts |>
ggplot(aes(x = year, y = count_districts, group = audit_flag)) +
geom_line(aes(color = audit_flag)) +
ylim(0,1000)
How have local districts changed?
sped %>%
filter(cntyname == "BASTROP") %>%
ggplot(aes(x = year, y = sped_percent, group = distname)) +
geom_line(aes(color = distname))
sped %>%
filter(cntyname == "HAYS") %>%
ggplot(aes(x = year, y = sped_percent, group = distname)) +
geom_line(aes(color = distname))
sped %>%
filter(cntyname == "TRAVIS") %>%
ggplot(aes(x = year, y = sped_percent, group = distname)) +
geom_line(aes(color = distname))
sped %>%
filter(cntyname == "WILLIAMSON") %>%
ggplot(aes(x = year, y = sped_percent, group = distname)) +
geom_line(aes(color = distname))