usmap ggplot2 - 映射美国县,传奇标题困难

时间:2017-11-26 15:11:23

标签: r ggplot2 usmap

我正在使用usmap库,它似乎可以很好地映射R中的县。但是,我有1个问题,因子地图的图例标题。

scale_color_gradient(low="green",high="darkgreen",name="My Factor")中使用名称并不起作用。 有趣的是,它适用于scale_fill_continuous(low="green", high="darkred", guide="colorbar",na.value="lightgray",name = "My Measure")

good legend bad legend

思想?

这再现了问题:

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 个答案:

没有答案