"BioGeoNick" is R code for plotting where I've travelled over my lifetime. It is authored by Nicholas J. Matzke.
This is very beta, but might be useful to someone (or to me in the future after I've lost where I saved this). If you use it, please cite something like:
- Matzke, Nicholas (2015). "BioGeoNick: R code for plotting personal geographic history on a map." PhyloWiki, http://phylo.wikidot.com/biogeonick
Inputs
The main input is an Excel worksheet with the columns "year", "latitude", and "longitude". (The script could be easily modified to load a tab-delimited text file with read.table). Just fill in these three items for each place you would like to be a point on the map. Locations will be plotted in order — year is just used to provide coloring.
Also, in the R script, to color visited coutnries grey, type in the names you've visited into the countries_visited list. The country names have to be exact matches to the country labels in the wrld_simpl map available in the R package maptools (see maptools::wrld_simpl). The country names are not always obvious, so to see them, type:
library(maptools)
data(wrld_simpl)
wrld_simpl$NAME
To get lat/long for map points, it is easiest to use a click-on-map service like: http://www.latlong.net/ .
Output
The output is a map, with lines connecting all of the points you've visited in your life, in the order you put them in the input table. I added a color scheme to distinguish older and newer events.
Here's mine. It could use some updates — it's difficult to remember everyplace I've been, and in the exact order, but this gets the overall picture pretty well.
(I made the legend & title manually in Keynote.)
Here, I've added the places I've given R workshops (BioGeoBEARS, BEASTmasteR, or otherwise):
Script
Here's the script.
#######################################################
# Make a map of Nick Matzke's world travels
#
# Using: http://www.latlong.net/
#
#######################################################
# Plot Great Circle paths:
# https://stat.ethz.ch/pipermail/r-sig-geo/2015-June/023032.html
library(geosphere)
library(gdata) # for read.xls
library(maptools) # for e.g. wrld_simpl
library(rgdal) # for e.g.
library(gpclib) # for polygon clipping
library(fields) # for colorbar.plot
wd = "/drives/GDrive/Matzke_PhD_docs/CV/_graphics/Matzke_map/"
setwd(wd)
xlsfn = "_Matzke_where_Ive_been_v1.xlsx"
xls = read.xls(xlsfn, header=TRUE, stringsAsFactors=FALSE)
head(xls)
tail(xls)
long_offset = -70
pdffn = "Matzke_map_v1.pdf"
pdf(file=pdffn, width=12, height=6)
data(wrld_simpl) #The world as a SpatialPolygonsDataFrame
#To avoid the lines crossing the map after reprojection we need to cut the polygons at the new break:
w <- nowrapRecenter(wrld_simpl, offset = 180+long_offset, avoidGEOS=TRUE)
#Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150°E as the new center)
CRS_string = paste0("+proj=robin +lon_0=", long_offset)
wrld_reCentered <- spTransform(w, CRS(CRS_string))
#wrld_reCentered2 <- spTransform(wrld_reCentered, CRS("+proj=longlat +lon_0=90"))
# Color countries by visiting
country_names = setNames(rep("white", length(wrld_simpl$NAME)), wrld_simpl$NAME)
country_colors <- setNames(rep("white", length(wrld_simpl$NAME)), wrld_simpl$NAME)
countries_visited = c("Germany",
"United States",
"Canada",
"Mexico",
"United Kingdom",
"France",
"Zimbabwe",
"Zambia",
"United Republic of Tanzania",
"Kenya",
"Greece",
"South Africa",
"Namibia",
"Lesotho",
"New Zealand",
"French Guiana",
"Brazil",
"Australia",
"Swaziland",
"Botswana",
"Finland",
"Turkey",
"Angola",
"Madagascar",
"China",
"Spain",
"Chile")
country_colors[countries_visited] = rep("grey70", times=length(countries_visited))
plot(wrld_reCentered, border="grey40", lwd=0.5, col=country_colors)
xls_original = xls
xls$latitude = jitter(xls$latitude)
xls$longitude = jitter(xls$longitude)
cols_for_lines = rainbow(n=nrow(xls))
for (i in 2:nrow(xls))
{
point1 = c(xls$longitude[i-1], xls$latitude[i-1])
point2 = c(xls$longitude[i], xls$latitude[i])
names(point1) = c("x","y")
names(point2) = c("x","y")
path = gcIntermediate(p1=point1, p2=point2, n=200, addStartEnd=TRUE, breakAtDateLine=TRUE)
if (is.null(dim(path)) == FALSE)
{
L1 = Line(path)
Ls1 = Lines(L1, ID="a")
SL1 = SpatialLines(list(Ls1), proj4string=CRS("+proj=longlat"))
SL1
#plot(SL1, add=TRUE)
lw <- nowrapSpatialLines(SL1, offset = 180+long_offset)
#Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150°E as the new center)
lwrld_reCentered <- spTransform(lw, CRS(CRS_string))
plot(lwrld_reCentered, add=TRUE, col=cols_for_lines[i], lwd=2)
#lines(sppoints, col=cols_for_lines[i])
#path = coordinates(path)
#sppoints = SpatialPoints(coords=path, proj4string=CRS("+proj=robin +lon_0=-80"))
#points(sppoints, col=cols_for_lines[i], add=TRUE)
}
if (is.null(dim(path)) == TRUE)
{
for (j in 1:length(path))
{
path2 = path[[j]]
#sppoints = SpatialPoints(coords=path2, proj4string=CRS("+proj=robin +lon_0=-80"))
#points(sppoints, col=cols_for_lines[i], add=TRUE)
#lines(sppoints, col=cols_for_lines[i])
L1 = Line(path2)
Ls1 = Lines(L1, ID="a")
SL1 = SpatialLines(list(Ls1), proj4string=CRS("+proj=longlat"))
SL1
lw <- nowrapSpatialLines(SL1, offset = 180+long_offset)
#Then proceed with the reprojection (note the proj4 string for a mollweide projection with 150°E as the new center)
lwrld_reCentered <- spTransform(lw, CRS(CRS_string))
plot(lwrld_reCentered, add=TRUE, col=cols_for_lines[i], lwd=2)
}
}
} # END for (i in 2:nrow(xls))
plot(0,0, pch=".", col="white", xlim=c(0,1), ylim=c(0,1))
stripvals <- ( 1:100)
colorbar.plot(x=0.5, y=0.5, strip=y, horizontal=FALSE)
dev.off()
cmdstr = paste0("open ", pdffn)
system(cmdstr)
Thanks
Thanks for help from:
http://stackoverflow.com/questions/27671710/how-to-color-selected-countries-in-wrld-simpl
And especially, this thread on the R-sig-geo list:
https://stat.ethz.ch/pipermail/r-sig-geo/2015-September/thread.html#23411