Trouble using plot_usmap() function in usmap package

775 Views Asked by At

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?

0

There are 0 best solutions below