I'm new to R and I'm trying to plot a data frame of county values using the usmap
library.
I have a dataset containing all the FIPS (county codes) for a particular region and the data (deaths) that I want to show on the map.
This is my first R script so what I'm trying to accomplish is likely pretty easy and I just have no idea what I'm doing.
I'm pretty sure the error I'm receiving is because I haven't specified any kind of coloring to apply to the data? I'm unsure.
Here's my code - note that I'm trying to initially just plot one frame of data (a particular date):
library(usmap)
library(ggplot2)
library(RColorBrewer)
#set working directory
setwd("C:/Users/Name/Documents/RScripts/")
#input data from file separated by commas
usa.dat <- read.csv("covid.csv", header = T)
#Start at 1/22/2020
#End at 10/8/2021
plot_usmap(regions = "counties",
data=usa.dat$countyFIPS,
values=usa.dat$X1.22.2020,
) +
theme(panel.background = element_rect(color = "black", fill = "black"))
Here's the data:
The error I'm getting is Error in if (is.null(geom_args[["fill"]]) & nrow(data) == 0) { : argument is of length zero
When I remove the data/values lines from the function, I get a map that looks like this:
Any help is greatly appreciated!
Ideally, I'd like to animate each frame of the data with color scales; if you guys can help me with that, I'd appreciate it!
Edit:
Okay so, I've been working on this for awhile and I managed to get it working. I have no idea how to update the color scales/gradients that are used, however.
I got it to loop through the data and save a bunch of plots, so that's pretty awesome! Just need to figure out how to change the colors/scales if anyone can help!