Why are these states not displaying the data when the data exists with the usmap package?

274 views Asked by At

I'm trying to plot election results on the US map with the usmap package but even though the dataset is complete, I get plot that shows missing values for some states. The states are greyed out and I'm not sure why this is happening..

enter image description here

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

enter image description here

1

There are 1 answers

2
r2evans On BEST ANSWER

You are incorrectly assuming that usmap will infer any format for state names. For instance, both of these produce a working map,

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

two states, take 1

whereas inferring from your pic of data, you are trying

usmap::plot_usmap(data=data.frame(state=c("alabama","new-york"),s=c(5,15)), values="s")
#                                                       ^ dash, not space

alabama alone

So I believe you need to clean up your data and fix your state names.