Hi everyone. I am trying to make a map in R. I want to display my output with a gradient fill, for example light colors for smaller populations in US states, and darker color for larger populations in US states (in the following code Ive changed the variable name to "variablename"). I was able to run the code without errors in previous versions or R, but now I keep running into this error:
"Error in check_aesthetics()
:
! Aesthetics must be either length 1 or the same as the data (790861): fill
Run rlang::last_error()
to see where the error occurred."
Here is my code:
a <- ggplot(map, aes(long, lat, group = group))+
geom_polygon(aes(fill ="variablename"), color="black")+
scale_fill_gradient(aes(low="white", high="navy"))+
theme_void() +
theme(plot.margin = unit(c(1,1,1,1), "cm"))
Im using a map with 10 different counties which has different values, so its really not an option to specify a color for each one. Does anyone know a way around this?
Best wishes