I am trying to fill a US map where each state is filled in by mean salary (In the default colour scale). I have the shapefile, and a dataframe which looks like this (Data falsified):
data <- structure(list(State = c("Arkansas",
"Iowa",
"California",
"Idaho"),
MeanSalary = c(50000,60000,62000,55000)),
row.names=1:4, class = "data.frame")
Here is my code:
library(tidyverse)
library(rgdal)
map <- readOGR(dsn = ".", layer = "usamap")
PlotData <- merge(map, data, by = "State")
This all works so far. I can also make an empty map:
map_base <- ggplot(data = PlotData, mapping=(aes(x=long, y = lat, group = group)) +
geom_polygon(color = "black", fill = NA)
map_base
However, I can't fill in the map with the values.
map_base <- ggplot(data = PlotData, mapping=(aes(x=long, y = lat, group = group)) +
geom_polygon(color = "black", fill = PlotData$MeanSalary)
map_base
I get this error:
Error: Aesthetics must be either length 1 or the same as the data (2834334): fill
What am I getting wrong?

