I am trying to make a plot of the rates of a type of exposure by regions using the following code. I don't need anything plotted by state, but instead would like to display the rates in each of the divisions defined below. The first map is just the regions I want. This seems to work fine. But when I try to overlay the rates I am getting crazy shapes in the map. Map works well, but when i overlay the rates it is not working at all. Does anyone have any suggestions to fix this?
library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)
library(maptools)
if (require("maps")) {
states <- map_data("state")}
us_state_map = map_data("state")
colnames(state_shape)
#map each state to a division
us_state_map$division[us_state_map$region %in% c("connecticut", "maine", "massachusetts", "new hampshire", "rhode island", "vermont")] <- "1"
us_state_map$division[us_state_map$region %in% c("district of columbia", "maryland", "new jersey","pennsylvania","west virginia" ,"delaware")] <- "2"
us_state_map$division[us_state_map$region %in% c("alabama","florida","georgia","arkansas","louisiana", "mississippi")] <- "3"
us_state_map$division[us_state_map$region %in% c("oklahoma","texas")] <- "4"
us_state_map$division[us_state_map$region %in% c("arizona","california","utah", "new mexico", "nevada")] <- "5"
us_state_map$division[us_state_map$region %in% c("alaska","idaho","oregon","washington","montana","hawaii")] <- "6"
us_state_map$division[us_state_map$region %in% c("illinois","north dakota","minnesota","south dakota","wisconsin")] <- "7"
us_state_map$division[us_state_map$region %in% c("colorado","iowa","kansas","missouri","nebraska", "wyoming" )] <- "8"
us_state_map$division[us_state_map$region %in% c("new york")] <- "9"
us_state_map$division[us_state_map$region %in% c("indiana", "michigan", "ohio")] <- "10"
us_state_map$division[us_state_map$region %in% c("north carolina","south carolina","tennessee", "kentucky", "virginia")] <- "11"
map <- ggplot()
map = map + geom_polygon(data=us_state_map, aes(x=long, y=lat, group=group, fill=division))
map
map <- ggplot()
map = map + geom_polygon(data=us_state_map.mod, aes(x=long, y=lat, group=group, fill=division))
map
map2<- map +
geom_polygon(data = regions_after, aes(x=long, y=lat, group=group, fill = percent_virtual)) +
geom_polygon(color = "black", fill = NA) + # get the state border back on top
theme_bw() +scale_fill_continuous(low="blue", high="red")+
ditch_the_axes
map2
after reading both comments, i think this is an appropriate sample: zz <-"division total percent_virtual long lat group region 1 1836 7.5163399 -70.22171 43.59063 18 maine 1 1836 7.5163399 -71.84318 41.34464 46 rhode island 1 1836 7.5163399 -70.6457 41.94624 21 massachusetts 1 1836 7.5163399 -72.20988 41.2988 6 connecticut 1 1836 7.5163399 -73.36152 45.01157 52 vermont 1 1836 7.5163399 -72.50208 42.9661 31 new hampshire 2 6451 1.7516664 -76.55862 38.42828 19 maryland 2 6451 1.7516664 -79.06245 42.00354 45 pennsylvania 2 6451 1.7516664 -74.72516 41.36755 32 new jersey