r - ggplot alter map fill opacity by second variable -
i'm creating cloropleth map of u.s each county colored proportion of 2012 votes obama. i'd vary opacity of county overlays population (similar done here). i've tried adding alpha = populationvariable geom_map aes, without luck.
here current code. can point me in right direction?
gg <- ggplot() gg <- gg + geom_map(data=mapc, map=mapc, aes(x=long, y=lat, map_id=id, group=group, fill=mapc$proportionobama)) gg = gg+ scale_fill_gradient2(limits= c(0,100), name="proportion of votes obama", low="#e5000a", high="#0012bf",mid="#720964", midpoint=50) gg = gg + theme_map() +coord_equal() gg <- gg + geom_path(data = maps, aes(long,lat, group=group), colour="gray50", size=.25) gg = gg + theme(legend.position="right") gg
i think alpha
needs variable that's mapped between 0 , 1. ggplot
documentation shows fractional value.
- hue scale - http://docs.ggplot2.org/0.9.3.1/scale_hue.html
- color fill alpha - http://docs.ggplot2.org/current/aes_colour_fill_alpha.html
you don't have reproducible code, here quick test seemed work.
library(data.table) library(ggplot2) tmp = data.table( 'x'=c(1,2,3), 'y'=c(1,2,3), 'z'=c(.1,.5,.8) ) p = ggplot() p = p + geom_point( data=tmp , aes(x=x,y=y,alpha=z)) print(p)
Comments
Post a Comment