2

I have decided to brush up on my map making skills and am using the publicly available COVID data from: https://www.kaggle.com/sudalairajkumar/covid19-in-usa

Below is my code:

USdata <- us_states_covid19_daily %>%
    group_by(state)%>%
    summarise(values = sum(positive))

#Assign each state its fips code using fips()
USdata$state <- as.numeric(fips(USdata$state))
USdata$values <- as.numeric(USdata$values)

#Rename columns appropriately
names(USdata)[names(USdata) == "state"] <- "fips"
USdata <- na.omit(USdata)

plot_usmap(data = USdata)

I keep receiving this error:

Error in `[.data.frame`(map_df, , values) : undefined columns selected

This is what my data frame looks like:

> head(USdata)
# A tibble: 6 x 2
   fips values
  <dbl>  <dbl>
1     2   1908
2     1  16845
3     5   9084
4     4  21232
5     6 128974
6     8  44905

My data frame could also look like this if I delete a line of code:

> head(USdata)
# A tibble: 6 x 2
  fips  values
  <fct>  <dbl>
1 AK      1908
2 AL     16845
3 AR      9084
4 AZ     21232
5 CA    128974
6 CO     44905

Anyone know what I'm doing wrong?

3
  • 1
    Strange...if you change your values column and call it X, and then add values = "X" to your plot_usmap call it seems to work
    – Ben
    Apr 8, 2020 at 23:53
  • That is very strange! Thank you for helping! I had tried everything BUT THAT :)
    – Angela C
    Apr 9, 2020 at 15:59
  • usmap developer here, this will be fixed in the upcoming 0.6.0 version, see here: github.com/pdil/usmap/pull/50
    – Paolo
    Feb 24, 2022 at 17:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.