library("dslabs")
data(package="dslabs")
list.files(system.file("script", package = "dslabs"))
##  [1] "make-admissions.R"                   
##  [2] "make-brca.R"                         
##  [3] "make-brexit_polls.R"                 
##  [4] "make-death_prob.R"                   
##  [5] "make-divorce_margarine.R"            
##  [6] "make-gapminder-rdas.R"               
##  [7] "make-greenhouse_gases.R"             
##  [8] "make-historic_co2.R"                 
##  [9] "make-mnist_27.R"                     
## [10] "make-movielens.R"                    
## [11] "make-murders-rda.R"                  
## [12] "make-na_example-rda.R"               
## [13] "make-nyc_regents_scores.R"           
## [14] "make-olive.R"                        
## [15] "make-outlier_example.R"              
## [16] "make-polls_2008.R"                   
## [17] "make-polls_us_election_2016.R"       
## [18] "make-reported_heights-rda.R"         
## [19] "make-research_funding_rates.R"       
## [20] "make-stars.R"                        
## [21] "make-temp_carbon.R"                  
## [22] "make-tissue-gene-expression.R"       
## [23] "make-trump_tweets.R"                 
## [24] "make-weekly_us_contagious_diseases.R"
## [25] "save-gapminder-example-csv.R"
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.0.6     v dplyr   1.0.4
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggthemes)
library(ggrepel)

For this homework, I’m using us_contagious_diseases dataset.

  1. Use filter to select Polio only and filter out NA values from Hawaii and Alaska

  2. Mutate the rate of Polio

Polio <- us_contagious_diseases %>%
  filter(disease == "Polio" & !state%in%c("Hawaii", "Alaska")) %>%
  mutate(rate = count / population * 10000 * 52 / weeks_reporting) %>%
  mutate(state = reorder(state, rate))
  1. Draw a heatmap using ggplot and geom_tile

  2. Draw a verticle line for 1955 which was the year Polio vaccine become available in the United States

  3. Add theme to the graph

  4. Add title and labels to the graph

Polio %>%
ggplot(aes(x = year, y = state, fill = rate)) +
  geom_tile(color = "grey50") +
  scale_x_continuous(expand=c(0,0))+
  scale_fill_gradient(low = "white", high = "purple", space = "Lab", na.value = "grey50") +
  geom_vline(xintercept = 1955, color = "red") +
  theme_classic(base_size = 9)+
  ggtitle("Heatmap for Polio in the US") +
  labs(x = "Year", y = "State")

For the second graph, I’m using death_prob dataset.

library(highcharter)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
## 
## Attaching package: 'highcharter'
## The following object is masked from 'package:dslabs':
## 
##     stars
library(RColorBrewer)
#view(greenhouse_gases)
  1. Draw the area graph with highchart

  2. Use RColorBrewer to set up the palette

  3. Add x and y axis label

  4. Change the legend position to upper right

  5. Add the chart title

  6. Customize the tooltips

highchart() %>%
  hc_add_series(data = greenhouse_gases, 
                type = "area", 
                hcaes(x = year, y = concentration, group = gas)) %>%
  hc_colors(brewer.pal(3, "Set2")) %>%
  hc_xAxis(title = list(text = "Year")) %>%
  hc_yAxis(title = list(text = "Gas Concentration (in ppm by volumn)")) %>%
  hc_legend(align = "right", verticalAlign = "top") %>%
  hc_title(text =  "Greenhouse Gas Concentration") %>%
  hc_tooltip(shared = TRUE, 
             borderColor = "black")