I am using ggplot2
to plot a map and points on top of it. This consists of plotting a map and then using geom_point()
to place the points on. Furthermore these points vary in size based on another variable. When I plot this it results in multiple legends.
ggplot(mapdata, aes(x=long, y=lat)) +
geom_map(map=mapdata, aes(map_id=region), fill="#ffffff", color="black", size=0.15) +
xlim(4, 15) +
ylim(47, 55) +
geom_point(data = dat, aes(long, lat, size = feature, alpha = 0.2, colour = "#007f3f")) +
scale_colour_manual(values = "#007f3f")
As explained in this question (and also this one) this can usually be achieved by using identical name
and labels
values for both scales however I am unsure how to apply this when the data is not being specified in the primary ggplot call (i.e. not in a geom) and with size as the legend. I have tried many iterations of this:
ggplot(mapdata, aes(x=long, y=lat)) +
geom_map(map=mapdata, aes(map_id=region), fill="#ffffff", color="black", size=0.15) +
xlim(4, 15) + ylim(47, 55) +
geom_point(data = dat, aes(long, lat, size = feature, alpha = 0.2, colour = "#007f3f")) +
scale_color_manual(name = "feature", values = "#007f3f", labels=c("1.0", "1.5", "2.0", "2.5", "3.0")) +
scale_size_manual(name = "feature", values = c(1.0, 1.5, 2.0, 2.5, 3.0), labels=c("1.0", "1.5", "2.0", "2.5", "3.0"))
How can I combine the legends?