library(dplyr)
library(ggplot2)
library(ggmap)
library(devtools)
library(stringr)
library(maps)
library(mapdata)
only_State<-read.delim("State.txt")
only_final<-read.delim("Final.txt")
df<-inner_join(only_State,only_final, by = c('State'))
devtools::install_github("dkahle/ggmap")
myStates <- subset(df, df$State %in% c("Texas", "Oklahoma","Arkansas", "Louisiana", "Mississippi", "Tennessee", "Kentucky", "Georgia","Florida","Delaware","Maryland","West Virginia","North Carolina","South Carolina","Alabama","Virginia"))
# ggplot(myStates, aes(Race, Deaths.y/Population.y, color=Race))+geom_count(stat = "identity")+facet_grid(~State)
usa<-map_data("usa")
states<-map_data("state")
map_states<-subset(states, region %in% c("texas", "oklahoma","arkansas", "louisiana", "mississippi", "tennessee", "kentucky", "georgia","florida","delaware","maryland","west virginia","north carolina","south carolina","alabama","virginia"))
myStates$region=tolower(myStates$State)
# ggplot(data=map_states)+ geom_polygon(aes(x=long,y=lat,group=group),fill="palegreen",color="black")+coord_fixed(1.3)+theme_bw()
graph_data<-inner_join(map_states,myStates)
# graph_data$Crude.Rate.y<-factor(graph_data$Crude.Rate.y,sort(unique(levels(graph_data$Crude.Rate.y))))
ggplot(data=graph_data)+ geom_polygon(aes(x=long,y=lat,group=group, fill=Crude.Rate.y),color="black")+coord_fixed(1.3)+theme_bw()+facet_grid(~Race)+labs(title="Opioid Death rates by race in the south" ,x='',y='')+theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(), axis.title.y=element_blank(), axis.text.y = element_blank(), axis.ticks.y=element_blank())

# The dataset used was pulled from the cdc website and was broken up by state and race and rates of death from opiod use based on the different state and racial demographic. Our group broke up the different areas of the united states, I am looking at the southern region of the US. I am working on a way to visualize the death rate as a continuois variable while also allowing for the unreliable option to be displayed. The crude rate is the death rate of the population. MY apologies for the compactedness of the graphs still trying to figure this package out.