Today we are going to take a look at the BART website and look at the visualizations presented on the website analytics.bart.gov.

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 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.

library(tidyverse)
library(jsonlite)

Read in the json data.

json_file <- "devices.json"
json_data <- fromJSON(json_file)
json_data

Fix the visits column so that it is a numeric value.

json_data <- json_data %>% mutate(visits = as.numeric(visits))
json_data

Make a table of the most recent day’s data.

json_data %>% filter( date == "20190922" ) %>%
  group_by(device) 

Make a bar plot.

json_data %>% filter( date == "20190922" ) %>%
  ggplot(aes(y = visits, x = device)) +
  geom_bar(stat="identity")

Make a bar plot using percentages.

json_data <- json_data %>% filter( date == "20190922" ) %>%
  mutate(visits_percentage = 100*visits/sum(visits))
json_data
json_data %>% ggplot(aes(y = visits_percentage, x = device)) +
  geom_bar(stat="identity") +
  coord_flip()

LS0tCnRpdGxlOiAiQkFSVCBhbmQganNvbiBkYXRhIgpvdXRwdXQ6CiAgd29yZF9kb2N1bWVudDogZGVmYXVsdAogIGh0bWxfbm90ZWJvb2s6IGRlZmF1bHQKICBwZGZfZG9jdW1lbnQ6IGRlZmF1bHQKLS0tCgpUb2RheSB3ZSBhcmUgZ29pbmcgdG8gdGFrZSBhIGxvb2sgYXQgdGhlIEJBUlQgd2Vic2l0ZSBhbmQgbG9vayBhdCB0aGUgdmlzdWFsaXphdGlvbnMgcHJlc2VudGVkIG9uIHRoZSB3ZWJzaXRlIFthbmFseXRpY3MuYmFydC5nb3ZdKGh0dHBzOi8vYW5hbHl0aWNzLmJhcnQuZ292L2JhcnQpLgoKV2Ugd2lsbCB0YWtlIGEgbG9vayBhdCAqanNvbiogZm9ybWF0ZWQgZGF0YSwgd2hpY2ggaXMgYSB2ZXJ5IGNvbW1vbiBkYXRhIGZvcm1hdCBmb3Igc2hhcmluZyBkYXRhIG9uIHRoZSBpbnRlcm5ldC4KCiMjIERpcmVjdGlvbnM6CgoxL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