usmap ggplot2 - mapping USA counties, legend title difficulties

Viewed 1528

I am using the usmap library which seems to do a great job of mapping counties in R. However, I have 1 issue, the legend titles for maps of factors.

Using name in scale_color_gradient(low="green",high="darkgreen",name="My Factor") doesn't work. Interestingly, it works in scale_fill_continuous(low="green", high="darkred", guide="colorbar",na.value="lightgray",name = "My Measure")

good legend bad legend

Thoughts?

This reproduces the problem:

require(usmap)
require(ggplot2)

d=data.frame(fips=as.integer( c(10001 ,10003 ,10005,  1001 , 1003 , 1005)))
d$measure=d$fips

plot_usmap(regions = 'counties',data=d, value='measure',lines=NA)+
  scale_fill_continuous(low="green", high="darkred", 
                        guide="colorbar",na.value="lightgray",name = "My Measure")+
  ggtitle('Legend title is correct')

d$measure=as.factor(d$fips) #simulate a factor
plot_usmap(regions = 'counties',data=d, value='measure',lines=NA)+
  scale_color_gradient(low="green",high="darkgreen",name="My Factor")+
  ggtitle('Notice the legend title is not correct')+
  theme(legend.position="bottom") 
0 Answers
Related