1

Hi I created a usmap using

plot_usmap(regions="counties",data=big.covid,values = "density")+
  labs(title="Unweighted Density by County")+
  theme(panel.background = element_rect(color="black"))+
  scale_fill_continuous(low="white",high="darkblue", name="Density")

rather than knitting, I get this error: Error in [.data.frame(result, , c(setdiff(names(result), names(data)), : undefined columns selected

any idea of how to identify the error and fix it? There are 59 variables would the issue be in a colname not being used in the map above? using x=x,y=y,id=fips which are built into the plot_usmap call

Lynn M
  • 21
  • 2
  • the message error speaks by itself: make sure that the variables names `counties` and `density` actually exists as column (case sensitive) in your data. – Jrm_FRL Apr 24 '20 at 14:24
  • Check the [documentation](https://cran.r-project.org/web/packages/usmap/vignettes/mapping.html). The issue is definitely related to `values="density"`, and I would suggest to ensure `bid.covid$density` exists and is numeric. `regions="counties"` should not be the issue. Note if you want to get a list of the counties used in the map, it should be accessible via: `usmap::us_map(regions='counties')$county` based on the documentation provided. – chemdork123 Apr 24 '20 at 15:22
  • Oddly, it was buried in the documentation, apparently, when I use plot_usmaps I can only pipe in two columns of data at a time so once I reduced the data by piping in only FIPS and density from the larger data file it ran fine and the error disappeared. The error message was confusing. – Lynn M Apr 26 '20 at 17:10

1 Answers1

1

I found the answer to this issue. The documentation mentions that if you use data in the map you can only use two columns and one has to be FIPS or state. Initially, I thought this meant I could only use one variable, but it is literal, so I piped in two columns from the larger data file:

`big.covid %>%
   select(fips, density)%>% 
 plot_usmap(regions="counties",data=big.covid,values = "density")+
   labs(title="Unweighted Density by County")+
   theme(panel.background = element_rect(color="black"))+
   scale_fill_continuous(low="white",high="darkblue", name="Density")`
Lynn M
  • 21
  • 2