US_state <- map_data("state") %>%
tbl_df()
US_county <- map_data("county") %>%
tbl_df()
US_county<- US_county %>% mutate(region, region = clean_text(region)) %>%
mutate(subregion, subregion = clean_text(subregion))
census <- read.csv("US_data.csv")
cesus_clean <- census %>%
mutate(pjew = as.numeric(as.character(census$per_jew))) %>%
mutate(county = clean_text(county))
county_state <- data.frame(str_split_fixed(cesus_clean$county, "county", 2))
census$county <- county_state$X1
census$state <- county_state$X2
census <- census %>% select(county,state,per_jew)
census$per_jew <- as.numeric(as.character(census$per_jew))
census_coor <- right_join(US_county, census,
by = c("region" = "state", "subregion" = "county"))
## Warning: Column `region`/`state` joining character vector and factor,
## coercing into character vector
## Warning: Column `subregion`/`county` joining character vector and factor,
## coercing into character vector
census_coor <- mutate(census_coor, pjew = per_jew/100)
map <- ggplot(data=NULL) +
geom_polygon(data = census_coor, aes(x=long, y=lat, group=group, fill = pjew)) +
geom_path(data=US_state, aes(x=long, y=lat, group=group), col="#636363", size=0.2) +
scale_fill_gradientn(name="Proportion Jewish",
colours = c("#f7fcb9", "#2c7fb8"),
values = (c(0,0.05, 0.1, 0.2, 0.3, 0.5, 1))) +
theme(panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.background = element_blank())
ggplotly(map)