library(shiny)
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
library(tidyr)
library(ggplot2)
library(tibble)
file<- "https://raw.githubusercontent.com/VioletaStoyanova/Data608/HW/cleaned-cdc-mortality-1999-2010-2.csv"
download.file(file,destfile = "~/cleaned-cdc-mortality-1999-2010-2.csv")
path<- file.path("cleaned-cdc-mortality-1999-2010-2.csv")
data<- read.csv(file = "https://raw.githubusercontent.com/VioletaStoyanova/Data608/HW/cleaned-cdc-mortality-1999-2010-2.csv", header= TRUE, stringsAsFactors=TRUE, sep = ",")
as_tibble(head(data))
## # A tibble: 6 x 6
## ICD.Chapter State Year Deaths Population Crude.Rate
## * <fct> <fct> <int> <int> <int> <dbl>
## 1 Certain infectious and parasit… AL 1999 1092 4430141 24.6
## 2 Certain infectious and parasit… AL 2000 1188 4447100 26.7
## 3 Certain infectious and parasit… AL 2001 1211 4467634 27.1
## 4 Certain infectious and parasit… AL 2002 1215 4480089 27.1
## 5 Certain infectious and parasit… AL 2003 1350 4503491 30.0
## 6 Certain infectious and parasit… AL 2004 1251 4530729 27.6
round((cor(sapply(data, as.integer), use = "complete.obs")), 3)
## ICD.Chapter State Year Deaths Population Crude.Rate
## ICD.Chapter 1.000 0.000 0.009 0.048 0.024 0.086
## State 0.000 1.000 0.000 -0.026 -0.077 0.010
## Year 0.009 0.000 1.000 0.001 0.027 -0.016
## Deaths 0.048 -0.026 0.001 1.000 0.386 0.626
## Population 0.024 -0.077 0.027 0.386 1.000 -0.032
## Crude.Rate 0.086 0.010 -0.016 0.626 -0.032 1.000
dataQ1 <- data %>%
filter(Year == 2010) %>%
group_by(State, ICD.Chapter) %>%
mutate(Count = sum(Deaths), Crude.Rate = 10^5 * (Count / Population))
## Warning: package 'bindrcpp' was built under R version 3.4.4
head(dataQ1)
## # A tibble: 6 x 7
## # Groups: State, ICD.Chapter [6]
## ICD.Chapter State Year Deaths Population Crude.Rate Count
## <fct> <fct> <int> <int> <int> <dbl> <int>
## 1 Certain infectious and p… AL 2010 1358 4779736 28.4 1358
## 2 Certain infectious and p… AK 2010 88 710231 12.4 88
## 3 Certain infectious and p… AZ 2010 1249 6392017 19.5 1249
## 4 Certain infectious and p… AR 2010 731 2915918 25.1 731
## 5 Certain infectious and p… CA 2010 5090 37253956 13.7 5090
## 6 Certain infectious and p… CO 2010 722 5029196 14.4 722