--- title: "BART and json data" output: word_document: default html_notebook: default pdf_document: default --- Today we are going to take a look at the BART website and look at the visualizations presented on the website [analytics.bart.gov](https://analytics.bart.gov/bart). We will take a look at *json* formated data, which is a very common data format for sharing data on the internet. ## Directions: 1. Create an R Project call BART. 2. Download the [devices](https://www.bart.gov/sites/default/files/analytics/devices.json) data. 3. Try the following R code to make the bar graph for the devices used to access the BART website. Load the libraries used. ```{r} library(tidyverse) library(jsonlite) ``` Read in the json data. ```{r} json_file <- "devices.json" json_data <- fromJSON(json_file) json_data ``` Fix the visits column so that it is a numeric value. ```{r} json_data <- json_data %>% mutate(visits = as.numeric(visits)) json_data ``` Make a table of the most recent day's data. ```{r} json_data %>% filter( date == "20190922" ) %>% group_by(device) ``` Make a bar plot. ```{r} json_data %>% filter( date == "20190922" ) %>% ggplot(aes(y = visits, x = device)) + geom_bar(stat="identity") ``` Make a bar plot using percentages. ```{r} json_data <- json_data %>% filter( date == "20190922" ) %>% mutate(visits_percentage = 100*visits/sum(visits)) json_data ``` ```{r} json_data %>% ggplot(aes(y = visits_percentage, x = device)) + geom_bar(stat="identity") + coord_flip() ```