---
title: "TNTP Data Memo"
author: "Analyst at TNTP"
date: "`r Sys.Date()`"
output:
  word_document:
    fig_caption: yes
    reference_docx: tntp-style-file.docx
    toc: no
---

<!-- Initializing knitr -->
```{r setup,echo=FALSE}
# Load packages, set options
if (!require("pacman")) install.packages("pacman"); library(pacman)
pacman::p_load(readxl, readr, tidyverse, janitor, lubridate, stringr) # add more here as needed
pacman::p_load_gh("tntp/tntpr", "amaier/reviewr", "adamMaier/tntpmetrics")

set_data_memo_formatting() # sets some common knitr chunk options
```

<!-- Import data file(s) -->

```{r import_data, include = FALSE}

# Import cleaned data file(s)
# Note: Use a common subdirectory structure
# Uncomment next line and change path to cleaned data file(s)
# read_csv(here("data/clean/my-file.csv"))

```

<!-- The next line is a horizontal rule -->
***


<!------------------------ Executive Summary ------------------------>
##### Page Break

Section Heading
=======================

Text...

Subheading
--------------------------------------------------------

Text of the report

* Key finding 1

* Key finding 2


<br/> <!--  The <br/> tag is a way to introduce vertical spacing -->

<!-- Use inline R and the function tableN to create a table caption.-->
`r tableN("Distribution of students by grade")`

```{r print_results_1, include=TRUE, echo=FALSE}

wisc %>%
  tabyl(grade) %>%
  mutate(percent = scales::percent(percent)) %>%
  kable(col.names = c("Grade", "Count", "Percent"), 
        align     = c("l", "c", "r"), 
        digits    = 2)

```

<br/>

Here's how proficiency changed over time for different grades:
<br/>

```{r print_results_2, include=TRUE, echo = FALSE, message = TRUE, fig.cap=figureN("Change in student proficiency")}

prof_by_grade_by_time <- wisc %>%
  mutate(grade = as.factor(grade)) %>%
  group_by(grade, year) %>%
  summarise(pct_prof = sum(proflvl %in% c("proficient", "advanced")) / sum(!is.na(proflvl)))
  
ggplot(prof_by_grade_by_time, aes(x = year, y = pct_prof, fill = grade)) +
  geom_bar(stat = "identity") +
  facet_grid(grade ~ .) +
  theme_tntp() +
  scale_fill_manual(values = palette_tntp("dark_blue", "medium_blue", "light_blue", "green", "gold", "medium_gray")) +
  labs(x     = "Year", 
       y     = "Percent Proficient", 
       title = "Student Proficiency Levels by Grade over Time") +
  scale_y_continuous(labels = scales::percent)

```

