I want to build a form file using ggplot2 in R. More specifically, I want to build the% whites living in each block for several major cities. So far I have been working with New Haven. The problem is that some blocks are not populated, in which case% white = NA. Ggplot automatically draws these blocks in gray. I would like to draw them in white.
New Haven with Gray NAs
c_opts <- theme(axis.text.x=element_blank(), axis.text.y=element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank(), axis.ticks = element_blank(), legend.text=element_text(size=10), legend.background=element_blank(), legend.key=element_rect(fill='transparent', colour=NA), panel.grid.major=element_line(colour='white'), panel.background=element_rect(fill='transparent', colour=NA), legend.justification=c(0,0), legend.position=c(.15,.15), legend.title=element_text(size=11, face='bold')) map <- qplot(PolyCoordsY, PolyCoordsX, data=nh_geom, group=Poly_Name, fill = pc_nhwhite, geom="polygon", xlab = "", ylab = "", main = "New Haven") map + c_opts + scale_fill_gradient(name = "% White")
I can exclude NA by adding na.value = NA to the argument to scale_fill_gradient.
map <- qplot(PolyCoordsY, PolyCoordsX, data=nh_geom, group=Poly_Name, fill = pc_nhwhite, geom="polygon", xlab = "", ylab = "", main = "New Haven") map + c_opts + scale_fill_gradient(name = "% White", na.value = NA)
New Haven with NA Excluded
Although it draws NA blocks in white, it also eliminates the polygon boundaries of these blocks. Does anyone know how to maintain the contours of a polygon?