I have created a map of the labor mobility in Spain in 2014. I have followed this link to adapt the code: http://www.r-bloggers.com/mapping-flows-in-r/
Now, I would like to add the names of the cities to the map. Any ideas?
Here is the code I used:
# Load the data about the labor flow
input <- read.csv("~/Desktop/flujo.csv", sep=";")
# Now we need to associate the Spanish regions with geographical coordinates.
centroids <- read.csv("~/Desktop/coordinates.csv", sep=";")
# Join the coordinates with the cities
or.xy<- merge(input, centroids, by.x="origin", by.y="origin")
or.xy$o_name<-or.xy$origin
names(or.xy)<- c("origin", "destination", "trips", "oX", "oY","o_name")
dest.xy<- merge(or.xy, centroids, by.x="destination", by.y="origin")
dest.xy$d_name<-dest.xy$destination
names(dest.xy)<- c("origin", "destination", "trips", "oX", "oY","o_name", "dX", "dY","d_name")
# Now for plotting with ggplot2.This first step removes the axes in the resulting plot.
xquiet<- scale_x_continuous("", breaks=NULL)
yquiet<-scale_y_continuous("", breaks=NULL)
quiet<-list(xquiet, yquiet)
# Let’s build the plot. First we specify the dataframe we need, with a filter excluding flows of <10
mapa<-ggplot(dest.xy[which(dest.xy$trips>1),], aes(oY,oX))+
# The next line tells ggplot that we wish to plot line segments. The “alpha=” is line transparency and used below
geom_segment(aes(x=oX, y=oY,xend=dX, yend=dY, alpha=trips), col="white")+
# Here is the magic bit that sets line transparency – essential to make the plot readable
scale_alpha_continuous(range = c(0.07,0.07))+
# Set black background, remove axes and fix aspect ratio
theme(panel.background = element_rect(fill="black",colour='black'))+quiet+coord_equal()