I am trying to create a choropleth
map in R using zipcode polygon data from TIGER database (using a response posted previously). The issue I am running into are large areas of the map that are blank.
I want to know if there are
a) other polygon data that are more complete than TIGER
b) other packages to construct a similar map without the blanks or
c) fill the blank spaces with custom color?
Code below:
library(ggplot2)
library(zipcode)
library(RColorBrewer)
library(tidyverse)
library(rgdal)
data(zipcode)
wazip <- zipcode[(zipcode$state=="WA"),]
wazip$numbers <- c(1:756) #Random values to plot
map.df <- readOGR(dsn = "", layer = "tl_2015_us_zcta510")#Import zipcode polygon data
combined <- map.df[map.df$ZCTA5CE10 %in% wazip$zip,] #extract zip codes in WA
mapfortified <- fortify(combined) #fortify map
map.data <- data.frame(id=rownames(combined@data),ZIP=combined@data$ZCTA5CE10) #extract zip and ID
map.data <- map.data %>% rename(zip = ZIP) #rename
map.data <- merge(map.data, wazip, by='zip') #merge my data by zip
map.df2 <- merge(mapfortified, map.data, by='id') #merge to fortified data
states <- readOGR(dsn="","gz_2010_us_040_00_5m") #load state polygon data
states <- states[states$NAME %in% c("Washington"),] #extract Washington`enter code here`
states.df <- fortify(states)
ggMap <- ggplot(data = map.df2, aes(long, lat, group=map.df2$group)) +
theme_classic()
ggMap <- ggMap + geom_polygon(aes(fill = numbers))
ggMap <- ggMap + geom_path(data=states.df, aes(x=long,y=lat,group=group))
ggMap <- ggMap + scale_fill_gradientn(name="Numbers",colours=brewer.pal(9,"Reds"))
ggMap <- ggMap + coord_equal()
ggMap