I am trying to create a map, showing data on a certain metric in 2007, with the colour on a gradient rather than banded.
The response showed here from SlowLearner (with the blue map) looks like it would get the results I want, so I have adapted this, but I am struggling to make this work.
The issue currently is that when I run the final line of code, I get the following error:
Error: Aesthetics must be either length 1 or the same as the data (1619341): group, x, y, fill
Here is my code, edited to anonymise the data.
EDIT: I've updated the code, replicated below, and now I get a map but it's all in one colour with no legend.
datafile <- rio::import("csv file from computer", header=TRUE)
shapefile <- readOGR(dsn="shapefile folder from computer", layer = "shapefile doc")
datafile <- datafile[order(datafile$region),]
shapefile <- shapefile[order(shapefile$region),]
mergedfile <- append_data(shapefile, datafile, key.shp="region", key.data="region", ignore.duplicates=TRUE)
ggplot(mergedfile, aes(x = long, y = lat), group = group, fill = mergedfile$"2007") +
geom_polygon(colour = "black", size = 0.5, aes(group = group)) +
theme()
I've searched and I can't work out what this means or what I need to change to make this work. Help appreciated!