I have an sf-object that I would like to plot. It is a map over counties in Sweden (21 counties) and for each county, I have a value. This value however can be either a positive or negative value, or even an NA. I would like to plot the map over Sweden and color all counties that have NA as white, and then color all other counties with a gradient (depending on value) for all the continuous values. But when I try I only get this error message: Error: Continuous value supplied to discrete scale
This is not my real data but I am not sure how to demonstrate sf-object. So here is just a dataframe with name of county and values (so no coordinates or anything):
data <- data.frame(Diff = c("NA", "NA", "5", "6.89", "9", "-4", "3.56"),
County = c("Halland", "Gotland", "Skane", "Jonkoping", "Gotaland",
"Blekinge", "Dalarna"))
ggplot(data) +
geom_sf(aes(fill = Diff), color = "black") +
scale_fill_manual(values = c("blue", "yellow", viridis::viridis(4))) +
coord_sf(datum = NA)
So I would like to plot the whole map and if a county have an NA, the county should be white. And then I would like to have different color gradient for the values (ranged from negative to positive values) for each county.
Have enayone experienced the same problem?