当数据存在于 usmap 包中时,为什么这些状态不显示数据?
Why are these states not displaying the data when the data exists with the usmap package?
我正在尝试使用 usmap 包在美国地图上绘制选举结果,但即使数据集是完整的,我得到的绘图显示某些州的缺失值。状态显示为灰色,我不确定为什么会这样..
plot_usmap(data=data_total,values='percent_biden')+
scale_fill_continuous(low='red',high='blue',name='Percent for Biden')+
theme(legend.position='right')+
ggtitle(paste("Total Popular Vote of Final Results"))
您错误地假设 usmap
将 推断出 州名的任何格式。例如,这两者都会产生一个工作地图,
usmap::plot_usmap(data=data.frame(state=c("alabama","new york"),s=c(5,15)), values="s")
usmap::plot_usmap(data=data.frame(state=c("AL","NY"),s=c(5,15)), values="s")
而从您的数据图片推断,您正在尝试
usmap::plot_usmap(data=data.frame(state=c("alabama","new-york"),s=c(5,15)), values="s")
# ^ dash, not space
所以我认为您需要清理数据并修正州名。
我正在尝试使用 usmap 包在美国地图上绘制选举结果,但即使数据集是完整的,我得到的绘图显示某些州的缺失值。状态显示为灰色,我不确定为什么会这样..
plot_usmap(data=data_total,values='percent_biden')+
scale_fill_continuous(low='red',high='blue',name='Percent for Biden')+
theme(legend.position='right')+
ggtitle(paste("Total Popular Vote of Final Results"))
您错误地假设 usmap
将 推断出 州名的任何格式。例如,这两者都会产生一个工作地图,
usmap::plot_usmap(data=data.frame(state=c("alabama","new york"),s=c(5,15)), values="s")
usmap::plot_usmap(data=data.frame(state=c("AL","NY"),s=c(5,15)), values="s")
而从您的数据图片推断,您正在尝试
usmap::plot_usmap(data=data.frame(state=c("alabama","new-york"),s=c(5,15)), values="s")
# ^ dash, not space
所以我认为您需要清理数据并修正州名。