I am trying to plot a map with ggplot for the first time and I am having problems achieving what I have in mind.
First of all, I have a data frame where every country code is associated to a number. For example:
id count
US 2030
DE 1001
UA 730
SY 229
I would like to obtain a ggplot map where countries are colored by number range (for example: more than 2000 dark red, 1000-2000 red, 1000-600 orange, 600-200 yellow, less than 100 white). The color itself is not important, I just would like to have it becoming paler the lower the count is.
This is what I tried:
world_map <- map_data(map = "world")
world_map$region <- iso.alpha(world_map$region)
ggplot(df, aes(map_id = id)) +
geom_map(aes(fill = frequency), map = world_map) +
expand_limits(x = world_map$long, y = world_map$lat) +
scale_colour_manual(name = "counts", values = cols,
breaks = c(2000,1000,600,200),
labels=c("more than 2000","2000-1000","1000-600","600-200")) +
theme_void() +
coord_fixed()
When I try to execute this code I obtain the following error message
Don't know how to automatically pick scale for object of type function. Defaulting to continuous. Error: Aesthetics must be valid data columns. Problematic aesthetic(s): fill = frequency. Did you mistype the name of a data column or forget to add after_stat()?
Now I understand that there is a problem in how I set my parameters but I cannot find any solution to this in the internet (or maybe I am too much of a beginner to correctly understand it).
