I have used the ggplot2 package to create a world map, the png file of the
output is attached. The code I use is below:
library(ggplot2)
library(mapproj)
long_Min <- -180.0
long_Max <- 180.0
lat_Min <- -50.0
lat_Max <- 80.0
Width <- 12.0
Height <- 2.0*Width*(lat_Max-lat_Min)/(long_Max-long_Min)
windows(width = Width, height = Height,record = TRUE)
World_map_data <- map_data("world")
World_map_dataS <- subset(World_map_data, (long >= long_Min & long <= long_Max)
& (lat >= lat_Min & lat <= lat_Max))
#Europe_data <- map_data("europe")
O_lat <- runif(10, min=lat_Min, max=lat_Max)
O_long <- runif(10, min=long_Min, max=long_Max)
D_lat <- runif(10, min=lat_Min, max=lat_Max)
D_long <- runif(10, min=long_Min, max=long_Max)
Routes = data.frame(O_lat,O_long, D_lat,D_long)
g1 <- ggplot(World_map_dataS, aes(x=long, y=lat, group=group, fill=region)) +
geom_polygon(fill="white", colour="blue") +
coord_map("mercator")
g1
I have a list of shipments with the lat/long of the Origin cities and
destination cities in a dataframe Routes. A test example is shown below:
structure(list(O_lat = c(57.8440704662353, 43.4692783257924,
34.197948181536, -13.9658199064434, 28.1358464458026, 54.8644948145375,
54.7105941944756, 0.960986674763262, -9.04949014307931, 67.3708150233142
), O_long = c(-135.800734693184, -139.97953729704, 130.949327526614,
120.016278969124, -81.3588178250939, 107.188451411203, -166.396527299657,
6.01017326116562, 119.992827912793, 68.8450227119029), D_lat =
c(13.1392757641152,
-48.4003935428336, -18.0977397086099, 7.47306475648656, 38.8207479682751,
-6.95962310535833, 21.4299688511528, 77.7941568545066, -39.2934810533188,
-5.45942842029035), D_long = c(-161.594757176936, -8.55208304710686,
59.6322040446103, 16.3289373647422, -82.6615255884826, -150.326664168388,
-86.496180742979, -162.877350552008, -119.206758281216, -110.952316028997
)), class = "data.frame", row.names = c(NA, -10L))
this dataframe consists of 10 shipments. How do I add these shipments as
individual lines onto the world map. If I need to I can convert from lat & long
to map coordinates using the mercator projection equations. My issue is what
ggplot commands to use.
Thanks
Bernard McGarvey
Director, Fort Myers Beach Lions Foundation, Inc.
Retired (Lilly Engineering Fellow).
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.