knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(tpltheme)
library(magrittr)
library(ggplot2)
set_tpl_theme()

lapply(list.files("../images", full.names = TRUE), file.remove)

pth <- "C:/Users/jh111/Box/Partnerships/TWC/Projects/COVID19 Childcare/Data visuals/June 9"

caption <- "The bar represents enrollment rates in the medium scenario. Error bars represent enrollment rates under low and high scenarios. Low= ADA / licensed capacity; High= (ADA + one standard deviation)/ licensed capacity; Medium= mid point between high and low scenarios."
df <- readr::read_csv("../data/ada_06052020.csv") %>% 
  tidyr::gather(scenario, value, c(low_pct, med_pct, hi_pct)) %>% 
  dplyr::mutate(non_subsidy = ifelse(grepl("not accept subsidy",
                                           tolower(group_id)), TRUE, FALSE),
                subsidy = ifelse(non_subsidy, FALSE, TRUE),
                home_prvdr = ifelse(grepl("home", tolower(group_id)), TRUE, FALSE),
                center_prvdr = ifelse(home_prvdr, FALSE, TRUE),
                low_scen = ifelse(grepl("low", tolower(scenario)), TRUE, FALSE),
                med_scen = ifelse(grepl("med", tolower(scenario)), TRUE, FALSE),
                high_scen = ifelse(grepl("hi", tolower(scenario)), TRUE, FALSE),
                Scenario = dplyr::case_when(low_scen ~ "Low",
                                            med_scen ~ "Medium",
                                            high_scen ~ "High"),
                Scenario = ordered(Scenario, level = c("Low", "Medium", "High")),
                prvdr_type = ifelse(home_prvdr, "Home provider", "Center provider"),
                type = dplyr::case_when(grepl("Small Size", group_id) ~ "Small (0-50)",
                                        grepl("Medium Size", group_id) ~ "Medium (51-99)",
                                        grepl("Large Size", group_id) ~ "Large (100+)",
                                        grepl("Licensed Home", group_id) ~ "Licensed Home",
                                        grepl("Registered Home", group_id) ~ "Registered Home"),
                type = ordered(type, c("Small (0-50)", "Medium (51-99)", "Large (100+)", "Licensed Home", "Registered Home")),
                `Subsidy status` = ifelse(subsidy, "Subsidy", "Non-Subsidy"),
                value = value*100
                ) %>% 
  dplyr::select(-c(group_id))

tpl_theme <- function(p) {
  p <- p +
    theme_minimal() +
    theme(
       strip.text.x = element_text(
      size = 12, color = "black", face = "bold.italic"
      ),
    panel.grid.minor.y = element_blank(),
    panel.grid.major.x = element_blank(),
    plot.caption = element_text(size = 9,
                                hjust = 0,
                                margin = margin(t = 0.2,
                                                b = 0,
                                                unit = "cm"),
                                color = "#939184",
                                family="Arial"
                              )
      )  +
    scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, 20))

}

Average daily attendance as a percent of licensed capacity

df1 <- df %>% 
              dplyr::select(-c(low_scen, med_scen, high_scen, Scenario)) %>%
              tidyr::spread(scenario, value)

p <- ggplot(df1,
  aes(x = forcats::fct_relabel(type,
                               stringr::str_wrap,
                               width = 5),
      y = med_pct)) +
  geom_bar(aes(fill = `Subsidy status`),
           stat = "identity",
           position = "dodge", alpha = 0.7) +
  geom_errorbar(aes(
     x = forcats::fct_relabel(type,
                              stringr::str_wrap,
                              width = 5), color = `Subsidy status`,
                    ymin = low_pct,
                    ymax = hi_pct),
                width = 0.2, alpha = 0.9, size = 1.3, position = position_dodge(0.9)) +
  facet_wrap(. ~ prvdr_type, scales = "free_x") + 
  labs(x = "Provider type"
       ,y = "Percent"
       ,title = "ADA as a percent of licensed capacity by provider type and subsidy status"
       ,caption = stringr::str_wrap(caption, 90)
       )

p <- tpl_theme(p)



p1 <- ggplot(df %>% 
         dplyr::filter(home_prvdr) %>% 
         dplyr::select(-c(Scenario, med_scen, high_scen, low_scen)) %>% 
         tidyr::spread(scenario, value)
        , aes(x = forcats::fct_relabel(type,
                                    stringr::str_wrap,
                                    width = 5), y = med_pct)) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_errorbar(aes(x = forcats::fct_relabel(type,
                                    stringr::str_wrap,
                                    width = 5),
                    ymin = low_pct,
                    ymax = hi_pct),
                width = 0.2, alpha = 0.9, size = 1.3, position = position_dodge(0.9))
  facet_wrap(. ~ `Subsidy status`) + 
  labs(x = "Provider type"
      ,y = "Percent"
       ) +
  theme_minimal() +
  theme(
    panel.grid.major.x = element_blank(),
    strip.text.x = element_text(
      size = 12, color = "black", face = "bold.italic"
      )
    ) +
  ylim(0, 100)

p2 <- ggplot(df %>% 
         dplyr::filter(center_prvdr) 
         , aes(x = forcats::fct_relabel(type,
                                    stringr::str_wrap,
                                    width = 5), y = value, fill = Scenario)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(. ~ `Subsidy status`) + 
  labs(x = "Center size"
      ,y = "Percent"
       ) +
  theme_minimal() +
  theme(
    panel.grid.major.x = element_blank(),
    panel.grid.minor.y = element_blank(),
    strip.text.x = element_text(
      size = 12, color = "black", face = "bold.italic"
      )
    )  +
  ylim(0, 100)

p <- cowplot::plot_grid(p1, p2,
                   ncol = 1,
                   # labels = c('Home Providers', 'Center Providers'),
                   label_size = 12,
                   rel_widths = c(2, 2))
p
ggsave("../images/provider_type-supply_scenario-subsidy.png", dpi = 1200)
ggsave(file.path(pth, "provider_type-supply_scenario-subsidy.png"), dpi = 1200)
ggsave("../images/provider_type-supply_scenario-subsidy.svg")
p1 <- ggplot(df %>% 
         dplyr::filter(home_prvdr) 
        , aes(x = forcats::fct_relabel(type,
                                    stringr::str_wrap,
                                    width = 5), y = value, fill = Scenario)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(. ~ `Subsidy status`) + 
  labs(x = "Provider type"
      ,y = "Percent"
       ) +
  theme_minimal() +
  theme(
    panel.grid.major.x = element_blank(),
    strip.text.x = element_text(
      size = 12, color = "black", face = "bold.italic"
      )
    ) +
  ylim(0, 100)

p2 <- ggplot(df %>% 
         dplyr::filter(center_prvdr) 
         , aes(x = forcats::fct_relabel(type,
                                    stringr::str_wrap,
                                    width = 5), y = value, fill = Scenario)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(. ~ `Subsidy status`) + 
  labs(x = "Center size"
      ,y = "Percent"
       ) +
  theme_minimal() +
  theme(
    panel.grid.major.x = element_blank(),
    panel.grid.minor.y = element_blank(),
    strip.text.x = element_text(
      size = 12, color = "black", face = "bold.italic"
      )
    )  +
  ylim(0, 100)

p <- cowplot::plot_grid(p1, p2,
                   ncol = 1,
                   # labels = c('Home Providers', 'Center Providers'),
                   label_size = 12,
                   rel_widths = c(2, 2))
p
ggsave("../images/provider_type-supply_scenario-subsidy.png", dpi = 1200)
ggsave(file.path(pth, "provider_type-supply_scenario-subsidy.png"), dpi = 1200)
ggsave("../images/provider_type-supply_scenario-subsidy.svg")

Average daily attendance as a percent of licensed capacity home providers vs. center providers

p <- ggplot(df %>% 
         dplyr::filter(med_scen)
         , aes(x = forcats::fct_relabel(type,
                                    stringr::str_wrap,
                                    width = 5), y = value, fill = `Subsidy status`)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(. ~ prvdr_type, scales = "free_x") + 
  labs(x = "Provider type"
      ,y = "Percent"
      ,title = stringr::str_wrap("Average daily attendance as a percent of licensed capacity by provider type and subsidy status for the medium supply scenario", 70)
       )

p <- tpl_theme(p)

p
ggsave("../images/provider_type-medium_supply_scenario-subsidy.png", dpi = 1200)
ggsave(file.path(pth, "provider_type-medium_supply_scenario-subsidy.png"), dpi = 1200)
ggsave("../images/provider_type-medium_supply_scenario-subsidy.svg")
df1 <- df %>% 
  dplyr::filter(med_scen) %>% 
  dplyr::group_by(`Subsidy status`, prvdr_type) %>% 
  dplyr::summarise(avg_ada = mean(value))

p <- ggplot(df1
         , aes(x = prvdr_type, y = avg_ada, fill = `Subsidy status`)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(x = "Provider type"
      ,y = "Percent"
      ,title = stringr::str_wrap("Average daily attendance as a percent of licensed capacity by provider type and subsidy status under medium supply scenario", 70))

p <- tpl_theme(p)

p
ggsave("../images/avg-ada_medium-scenario_subsidy-status_provider-type.png", dpi = 1200)
ggsave(file.path(pth, "avg-ada_medium-scenario_subsidy-status_provider-type.png"), dpi = 1200)
ggsave("../images/avg-ada_medium-scenario_subsidy-status_provider-type.svg")
df1 <- df %>% 
  dplyr::group_by(prvdr_type, Scenario) %>% 
  dplyr::summarise(avg_ada = mean(value)) %>% 
  tidyr::spread(Scenario, avg_ada)

p <- ggplot(df1, aes(x = prvdr_type, y = Medium)) +
  geom_bar(stat = "identity",
           position = "dodge", alpha=0.7) +
  geom_errorbar(aes(x = prvdr_type,
                    ymin = Low,
                    ymax = High),
                width = 0.2, alpha = 0.9, size = 1.3, position = position_dodge(0.9)) +
 labs(x = "Provider type"
     ,y = "Percent"
     ,title = "ADA as a percent of licensed capacity by provider type"
     ,caption = stringr::str_wrap(caption, 120)
       )

p <- tpl_theme(p)

p
ggsave("../images/bar-error-bars_subsidy-status_provider-type-overall.png", dpi = 1200)
ggsave(file.path(pth, "bar-error-bars_subsidy-status_provider-type-overall.png"), dpi = 1200)
ggsave("../images/bar-error-bars_subsidy-status_provider-type-overall.svg")
df1 <- df %>% 
  dplyr::group_by(Scenario, prvdr_type) %>% 
  dplyr::summarise(avg_ada = mean(value))

p <- ggplot(df1
         , aes(x = prvdr_type, y = avg_ada, fill = Scenario)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(x = "Provider type"
      ,y = "Percent"
      ,title = stringr::str_wrap("Average daily attendance as a percent of licensed capacity by provider type and supply scenario", 70))

p <- tpl_theme(p)

p
ggsave("../images/avg-ada_supply-scenario_provider-type.png", dpi = 1200)
ggsave(file.path(pth, "avg-ada_supply-scenario_provider-type.png"), dpi = 1200)
ggsave("../images/avg-ada_supply-scenario_provider-type.svg")
df1 <- df %>% 
              dplyr::select(-c(low_scen, med_scen, high_scen, Scenario)) %>%
              tidyr::spread(scenario, value)

p <- ggplot(df1,
  aes(x = forcats::fct_relabel(type,
                               stringr::str_wrap,
                               width = 5),
      y = med_pct)) +
  geom_bar(aes(fill = `Subsidy status`),
           stat = "identity",
           position = "dodge", alpha = 0.7) +
  geom_errorbar(aes(
     x = forcats::fct_relabel(type,
                              stringr::str_wrap,
                              width = 5), color = `Subsidy status`,
                    ymin = low_pct,
                    ymax = hi_pct),
                width = 0.2, alpha = 0.9, size = 1.3, position = position_dodge(0.9)) +
  facet_wrap(. ~ prvdr_type, scales = "free_x") + 
  labs(x = "Provider type"
       ,y = "Percent"
       ,title = "ADA as a percent of licensed capacity by provider type and subsidy status"
       ,caption = stringr::str_wrap(caption, 90)
       )

p <- tpl_theme(p)

p
ggsave("../images/bar-error-bars_subsidy-status_provider-type.png", dpi = 1200)
ggsave(file.path(pth, "bar-error-bars_subsidy-status_provider-type.png"), dpi = 1200)
ggsave("../images/bar-error-bars_subsidy-status_provider-type.svg")


Texas-Policy-Lab/childcare_app documentation built on March 22, 2021, 12:42 p.m.