-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAffordable Care Act Data.R
65 lines (44 loc) · 1.9 KB
/
Affordable Care Act Data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Affordable Health Care Act Data
### Loading the Libaries
library(ggplot2)
library(maps)
library(zipcode)
library(ggmap)
library(choroplethrMaps)
library(choroplethr)
data("state.map")
### Changing the Working Directory
setwd('./Kaggle')
### Reading the Data
acadat <- read.csv(file='./states.csv', header = TRUE, sep = ",", strip.white = TRUE )
m <- colnames(acadat)
length(m)
acadat <- read.csv(file='./states.csv', header = FALSE, skip = 1, sep = ",", strip.white = TRUE )
n <- colnames(acadat)
head(acadat)
### Reading the Dictionary and Cleaning the Data
any(is.na(acadat))
dictionary <- cbind(n, m)
str(acadat)
# Strip percentages and dollars first
acadat[,c("V2", "V3", "V4")] <- (sapply(acadat[, c("V2", "V3", "V4")], function(x) as.numeric(gsub("%","", x))))
acadat$V9 <- gsub("\\$","", acadat$V9)
acadat$region = tolower(acadat$V1)
us_state_map = map_data('state');
map_data = merge(acadat, us_state_map, by = 'region')
map_data = arrange(map_data, order)
### Maps for the United States
ggplot(map_data, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = cut_number(V2, 6))) +
geom_path(colour = 'red') + labs(title = "State level insurance coverage in 2010") +
scale_fill_brewer('Uninsured Percent, 2010') + coord_map()
# Uninsured percent in 2015
ggplot(map_data, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = cut_number(V3, 6))) +
geom_path(colour = 'black', alpha = 0.5) + labs(title = "State level insurance coverage in 2015") +
scale_fill_brewer('Uninsured Percent, 2015') + coord_map()
# Uninsured rate change, 2010-15
ggplot(map_data, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = cut_number(V4, 6))) +
geom_path(colour = 'orange') + labs(title = "State level change in insurance coverage, 2010-15") +
scale_fill_brewer('Uninsured rate change, 2010-15') + coord_map()