I've produced this map in ggplot2
:
library(maptools); library(ggplot2)
data(wrld_simpl)
world <- fortify(wrld_simpl)
worldUk <- subset(world, id=="GBR")
ggplot() +
geom_path(aes(long, lat, group=group), data=worldUk, color="black", fill=NA) +
coord_equal()
Using photoshop, I've added a scale bar to the map. How can I add a similar scale bar using ggplot2
? This post adds a scale bar, but the bar doesn't refer to distance: scale bar and north arrow on map-ggplot2
There is a library called ggsn, which allows you to customize the scale bar and north arrow.
I would suggest annotate(), which would allow you to draw segments of the proper length right in the plotting area. You could then add text above/below as a label.
I found this answer on http://editerna.free.fr/wp/?p=76 and I found it simple and worked perfectly so I must share it!
It is simple, first paste the code below into your console (no need for editing)
Now, to plot onto a map!
First create your ggplot map, and add the scale bar as an extra layer, using the « + » sign:
On the example above, I call the « scaleBar » function, and I specify some values for the arguments. For instance, lon = -130, lat = 26 means I want the bottom left point of the rectangle to be at (-130,26). You need to define the other values of each argument according to what you want (there is a description of each argument in the header of the function).