'Adding directional indication to flow map in R
I'm just getting started on visualising data with R. I've been working on creating a flowmap based off lats and long data from origins and destination of various things. The data is in a .csv file. The map displays very nicely and the lines representing the flows are also there; however, I can't seem to get them to have directional indicators. Any help/idea would be great!
Here's the code which displays maps and lines:
library(maps)
library(geosphere)
library(sp)
library(maptools)
library(OpenStreetMap)
library(rgdal)
library(rgeos)
map <- openmap(c(70, -179), c(-70,179), type='bing', zoom=5)
map_longlat <- openproj(map, projection = "+proj=longlat")
plot(map_longlat,raster=TRUE)
flows <-read.csv("myfile", sep=",", header=TRUE)
for (i in 1:nrow(flows)){
inter<- gcIntermediate(c(flows$org_long[i], flwos$org_lat[i]), c(flows$dest)long[i], flows$dest_lat[i]), n=50, addStartEnd=TRUE)
lines(inter, col="red", lwd = 0 + c(flows$count[i])
}
Thanks!
Solution 1:[1]
Here is a simple solution using ggplot2
and curved lines. Note the argument arrow
. If you want a more professional map that uses the shortest route between locations considering the spherical curvature of the planet, here is a solution here.
ggplot() +
geom_curve(data = OD, aes(x = longitude.x, y = latitude.x,
xend = longitude.y, yend = latitude.y),
curvature = -0.2, arrow = arrow(length = unit(0.01, "npc"))) +
coord_equal()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | rafa.pereira |