3

我正在使用 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")

好传说 坏传说

想法?

这重现了问题:

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") 
4

0 回答 0