This lesson is called Other Formats, part of the R in 3 Months (Fall 2021) course. This lesson is called Other Formats, part of the R in 3 Months (Fall 2021) course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Loading transcript...
Your Turn
Solution
---title:"Report on Diversity in Oregon Schools"author:"David Keyes"date:"4/28/2020"params:race_ethnicity_category:"Hispanic/Latino"output: bookdown::gitbook---```{rsetup, include=FALSE}knitr::opts_chunk$set(echo=FALSE,message=FALSE,warning=FALSE,cache=TRUE)``````{r}library(tidyverse)library(scales)library(ggtext)library(extrafont)library(ggalt)library(janitor)library(gt)loadfonts()```# IntroductionThisisareportforthe [OregonDepartmentofEducation](https://www.oregon.gov/ode/pages/default.aspx) ondiversityinOregonschooldistricts. HereisthemissionstatementforODE:>TheOregonDepartmentofEducationfostersequityandexcellenceforeverylearnerthroughcollaborationwitheducators, partners, andcommunities.^[Source: [ODEWebsite](https://www.oregon.gov/ode/about-us/Pages/default.aspx)]# Growth Data## Table of GrowthThetablebelowshowsthedistrictswiththehighestgrowthoftheir`r params$race_ethnicity_category`studentpopulationfrom2017-2018to2018-2019. ```{r}enrollment_by_race_ethnicity<-read_rds("data/enrollment-by-race-ethnicity.rds")``````{r}options(scipen=999)enrollment_by_race_ethnicity%>%filter(race_ethnicity==params$race_ethnicity_category) %>%pivot_wider(id_cols=c(district, district_id),names_from=year,values_from=percent_of_total_at_school) %>%mutate(growth=`2018-2019`-`2017-2018`) %>%arrange(desc(growth)) %>%select(-district_id) %>%slice_max(growth, n=10) %>%gt() %>%cols_label(district="District",growth="Growth" ) %>%fmt_percent(columns=vars(`2017-2018`, `2018-2019`, growth),decimals=1 )```## Growth Chart```{r}highlight_district<-enrollment_by_race_ethnicity%>%filter(race_ethnicity=="Hispanic/Latino") %>%filter(district=="Douglas ESD") %>%mutate(percent_display=percent(percent_of_total_at_school, accuracy=1)) %>%mutate(percent_display=case_when(year=="2018-2019"~str_glue("{percent_display} Latino students"),TRUE~percent_display ))``````{rfig.cap="Test Caption", fig.width=10}theme_student<-function() {theme_minimal(base_family="Courier New") +theme(axis.title=element_blank(),panel.grid.minor.y=element_blank(),plot.title=element_markdown(face="bold"))}enrollment_by_race_ethnicity%>%filter(race_ethnicity=="Hispanic/Latino") %>%ggplot(aes(x=year,y=percent_of_total_at_school,group=district)) +geom_line(color="lightgray",alpha=0.5) +geom_line(data=highlight_district,inherit.aes=TRUE,color="blue") +geom_text(data=highlight_district,inherit.aes=TRUE,aes(label=percent_display),hjust=c(1, 0),family="Courier New",color="blue") +scale_y_continuous(labels=percent_format(),limits=c(0, 1)) +labs(title="<span style = 'color: blue'>Douglas ESD</span> saw a large growth in its Latino student population from 2017-2018 to 2018-2019") +annotate("text",x=2.02,y=.825,hjust=0,color="gray",family="Courier New",label="Woodburn has the highest\npercentage of Latino students\nof any district") +scale_x_discrete(expand=expansion(add=c(0.1, 0.5))) +theme_student()```## Growth Dumbbell Chart```{r}enrollment_by_race_ethnicity%>%filter(race_ethnicity=="Hispanic/Latino") %>%select(-c(race_ethnicity, number_of_students, district_id)) %>%pivot_wider(id_cols=district,names_from=year,values_from=percent_of_total_at_school) %>%clean_names() %>%slice(1:10) %>%ggplot(aes(x=x2017_2018,xend=x2018_2019,y=district,yend=district)) +geom_dumbbell(colour_x="gray",colour="gray",colour_xend="blue",size_x=3,size_xend=1.5) +theme_student() +scale_x_continuous(label=percent_format())```
To make a website using the distill package, check out this page on the distillwebsite. If you want to see a distill website in action, Tom Mock’s blog is made with it.
The best place to start with blogdown is the book blogdown: Creating Websites with R Markdown. One of the authors is Alison Hill, who I mentioned in the video has a lot of great material on blogdown. I’d suggest starting with her extensive blog post Up & Running with blogdown.
Dan Quintana also has a bunch of materials on getting started with blogdown, shown in this Twitter thread.
Every few days there’s a tweet asking how to make academic websites. This is great, everyone should have their own site! My guide is sometimes mentioned too, which is also great, but some don’t know I’ve made THREE versions: A thread, blog post, and video. Here they are ⤵️
#Load the librarieslibrary(tidyverse)library(hrbrthemes)library(scales)library(ggtext)library(extrafont)loadfonts()library(janitor)library(ggalt)library(dplyr)library(gt)library(pagedown)
#Load the dataenrollment_by_race_ethnicity%filter(district=="Beaverton SD 48J") %>%filter(year=="2018-2019") %>%ggplot(aes(x=percent_of_total_at_school,y=race_ethnicity)) +geom_col()
#How to create a line chart with geom points#Always check the space between the function and bracketsenrollment_by_race_ethnicity%>%filter(race_ethnicity==params$race_ethnicity_category) %>%ggplot(aes(x=year,y=percent_of_total_at_school,group=district)) +geom_point() +geom_line()highlight_district%filter(race_ethnicity=="Hispanic/Latino") %>%filter(district=="Douglas ESD")
#Use color to highlight findingshighlight_district%filter(race_ethnicity=="Hispanic/Latino") %>%filter(district=="Douglas ESD")enrollment_by_race_ethnicity%>%filter(race_ethnicity=="Hispanic/Latino") %>%ggplot(aes(x=year,y=percent_of_total_at_school,group=district)) +geom_line(color="lightgray",alpha=0.5) +geom_line(data=highlight_district,inherit.aes=TRUE,color="blue")
#Decluttering a graphenrollment_by_race_ethnicity%>
You need to be signed-in to comment on this post. Login.
Atlang Mompe • June 28, 2021
Hi David, this is my code below for this last exercise, can I ask why I did not get a book format based on my code:
title: "Report on Diversity in Oregon School" author: "Atlang Mompe" date: "
r Sys.Date()" params: race_ethnicity_category: "Hispanic/Latino" output: bookdown::gitbook