Summary

This project is created for the Unit 3 assignment of Developing Data Products certification course. The author downloaded the data of school improvement grants from https://catalog.data.gov/dataset/school-improvement-2010-grants and created an interactive map to show the grants to each state.

Downloading and preprocessing data

grants <- read.csv(url("https://inventory.data.gov/dataset/ce23c458-9c25-4bcc-a7bd-0490641dec8e/resource/9665a448-6f2f-4872-99b9-bf12b5af84f4/download/userssharedsdfschoolimprovement2010grants.csv"), header = TRUE)
head(grants)
##                         School.Name     City State
## 1 HOGARTH KINGEEKUK MEMORIAL SCHOOL SAVOONGA    AK
## 2                   AKIACHAK SCHOOL AKIACHAK    AK
## 3                    GAMBELL SCHOOL  GAMBELL    AK
## 4              BURCHELL HIGH SCHOOL  WASILLA    AK
## 5                      AKIAK SCHOOL    AKIAK    AK
## 6                    MIDVALLEY HIGH  WASILLA    AK
##                               District.Name X2010.11.Award.Amount
## 1             BERING STRAIT SCHOOL DISTRICT            $471014.00
## 2                    YUPIIT SCHOOL DISTRICT            $520579.00
## 3             BERING STRAIT SCHOOL DISTRICT            $449592.00
## 4 MATANUSKA-SUSITNA BOROUGH SCHOOL DISTRICT            $641184.00
## 5                    YUPIIT SCHOOL DISTRICT            $399686.00
## 6 MATANUSKA-SUSITNA BOROUGH SCHOOL DISTRICT            $697703.00
##   Model.Selected
## 1 Transformation
## 2 Transformation
## 3 Transformation
## 4 Transformation
## 5 Transformation
## 6        Restart
##                                                          Location
## 1            200 MAIN ST\nSAVOONGA, AK 99769\n(63.6687, -170.603)
## 2         AKIACHAK 51100\nAKIACHAK, AK 99551\n(60.8911, -161.376)
## 3             169 MAIN ST\nGAMBELL, AK 99742\n(63.7413, -171.689)
## 4     1775 WEST PARKS HWY\nWASILLA, AK 99654\n(61.5794, -149.495)
## 5                  AKIAK 5227\nAKIAK, AK 99552\n(60.8879, -161.2)
## 6 7362 WEST PARKS HWY 725\nWASILLA, AK 99654\n(61.5023, -149.796)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

grants$amount=as.numeric(gsub("\\$", "", grants$X2010.11.Award.Amount))
grants[is.na(grants)] <-0
head(grants)
##                         School.Name     City State
## 1 HOGARTH KINGEEKUK MEMORIAL SCHOOL SAVOONGA    AK
## 2                   AKIACHAK SCHOOL AKIACHAK    AK
## 3                    GAMBELL SCHOOL  GAMBELL    AK
## 4              BURCHELL HIGH SCHOOL  WASILLA    AK
## 5                      AKIAK SCHOOL    AKIAK    AK
## 6                    MIDVALLEY HIGH  WASILLA    AK
##                               District.Name X2010.11.Award.Amount
## 1             BERING STRAIT SCHOOL DISTRICT            $471014.00
## 2                    YUPIIT SCHOOL DISTRICT            $520579.00
## 3             BERING STRAIT SCHOOL DISTRICT            $449592.00
## 4 MATANUSKA-SUSITNA BOROUGH SCHOOL DISTRICT            $641184.00
## 5                    YUPIIT SCHOOL DISTRICT            $399686.00
## 6 MATANUSKA-SUSITNA BOROUGH SCHOOL DISTRICT            $697703.00
##   Model.Selected
## 1 Transformation
## 2 Transformation
## 3 Transformation
## 4 Transformation
## 5 Transformation
## 6        Restart
##                                                          Location amount
## 1            200 MAIN ST\nSAVOONGA, AK 99769\n(63.6687, -170.603) 471014
## 2         AKIACHAK 51100\nAKIACHAK, AK 99551\n(60.8911, -161.376) 520579
## 3             169 MAIN ST\nGAMBELL, AK 99742\n(63.7413, -171.689) 449592
## 4     1775 WEST PARKS HWY\nWASILLA, AK 99654\n(61.5794, -149.495) 641184
## 5                  AKIAK 5227\nAKIAK, AK 99552\n(60.8879, -161.2) 399686
## 6 7362 WEST PARKS HWY 725\nWASILLA, AK 99654\n(61.5023, -149.796) 697703
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.4
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
grantsSum <- grants[, c(3, 8)] %>%
  group_by(State) %>%
  summarise(grtSum = sum(amount))
grantsSum$grtSum <- prettyNum(grantsSum$grtSum, big.mark=",", preserve.width = "none")
grantsSum$grtSum <- as.numeric(gsub(",", "", grantsSum$grtSum))

Map the data

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.4
library(plotly)
## Warning: package 'plotly' was built under R version 3.4.4
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(dplyr)
map_options <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showlakes = TRUE,
  lakecolor = toRGB('white')
)

p <- plot_geo(grantsSum, locationmode='USA-states', z = ~grtSum, text = ~grtSum, locations = ~State, color =  ~grtSum, colors = 'Purples') %>% 
  layout(title = 'School Improvement Grants across the States in 2010', geo = map_options)

p
## Warning: package 'bindrcpp' was built under R version 3.4.4