Hägerstrand Time-Space Cube
11/30/2010
With the rgl package it’s possible to interact with the 3d visualization of the timespace tracks.
Code example:
plot3d(lon,lat,timedate, xlim=range(lon), ylim=range(lat), zlim=range(timedate), ticktype=”detailed”, xlab=”longitude”, ylab=”latitude”, zlab=”Date”, col= as.POSIXlt(daten[,”Date”])$mday, type=”l”, main=plottitle)
In the posted example individual waypoints were added by drawing vertical lines.
Many asked for the code. Here is some of it:
################################################# # 2.5 PLOT Hgerstrand TimeSpace 3d interaktiv ################################################# dimen <- dim(daten) dts = daten$Date tms = daten$Time timedate <- timeDate(paste(dts, tms), format = “%Y-%m-%d %H:%M:%S”, zone = “GMT”, FinCenter = “Europe/Berlin”) # timeDate Object erzeugen zshift = 180000 plottitle <- paste(proband, “TimeSpaceCube vom”, range(dts)[1], “bis”, range(dts)[2]) plot3d(lon,lat,as.numeric(timedate+zshift), xlim=range(lon), ylim=range(lat), lit=TRUE, box=FALSE, smooth=TRUE, alpha=c(1), zlim=as.numeric(range(timedate)+zshift), lwd=”3″, axes=T, xlab=””, ylab=””, zlab=””, fog=TRUE, col= as.POSIXlt(daten[,”Date”])$mday%%2+1, type = “l”) # Plot Hgerstrand timespace path / x=longitude , main=plottitle light3d(theta = 0, phi = 15) rgl.bg( sphere = FALSE, fogtype = “none”, color=c(“#FFFFFF”,”white”), back=”lines”) #plot3d(daten_wp$Longitude[6],daten_wp$Latitude[6], timedate[1], size=400, type=”p”) #grid3d(“z+”, at = NULL, col = “#888888″, lwd = 1, lty = 2, n = 8) plot3d(range(lon)[2],lat, timedate, xlim=range(lon), ylim=range(lat), zlim=range(timedate),col=”#CCCCCC”, lwd=”1″, add=T, type=”l”) #sideplot plot3d(lon,lat, range(timedate)[1], xlim=range(lon), ylim=range(lat), zlim=range(timedate),col=”#CCCCCC”, lwd=”1″, add=T, type=”l”) # GroundedPlot #grid3d(“z”, at = NULL, col = “#CCCCCC”, lwd = 1, lty = 2, n = 4) plot3d(daten_wp$Longitude,daten_wp$Latitude, timedate[1]+300, col=”darkgrey”, size=”5″, lwd=”3″, type=”p”, add=T) #plot3d(daten_wp$Longitude,daten_wp$Latitude, range(timedate)[2], col=”darkgrey”, size=”5″, lwd=”3″, type=”p”, add=T) rgl.texts(daten_wp$Longitude,daten_wp$Latitude,range(timedate)[2], color=”black”, text=daten_wp$wpOpen, adj = 0.5, family = “sans”, font = 1, cex = 1, useFreeType=F) daten_wp$id <- c(1:dim(daten_wp)[1]) for(ii in unique(daten_wp[,”id”])){ if (daten_wp$isConstraint[ii] == “TRUE”) { line1 <- c(daten_wp$Longitude[ii], daten_wp$Latitude[ii], as.numeric(timedate[1])[1]) line2 <- c(daten_wp$Longitude[ii], daten_wp$Latitude[ii], as.numeric(range(timedate)[2]+zshift)[1]) lineall <- rbind(line1,line2) lines3d(lineall, lwd=300, col=”black”, alpha=c(0.1)) } } aspect3d(1,1,1.5) # Jeder Proband unterschiedliche Werte zur Anonymisierung snapshot3d(paste(plotpath, proband, “_timespacecube.png”, sep=””)) for (i in 1:60) { count <- seq(1,90,1)[i] rgl.viewpoint(theta=0, phi=count) filename <- paste(plotpath, “\\timespaceani\\pic”,formatC(i,digits=1,flag=”0″),”.png”,sep=””) rgl.snapshot(filename) }
11/30/2010 at 3:48 pm
Hi,
this looks really nice! It would be great though, if your code was reproducible, so anyone interested can play around with it on their own computer…
Cheers,
Mark
11/30/2010 at 4:11 pm
Thank you for your interest. This type of visualization is not a big deal. Just install the rgl package and import some gps trackdata a cvs file. The tracks timestamps should be merged (Time+Date) to a timedate format which is possible with the timedate package. You can also take any other data with 3 dimensions like underground earthquake coordinates. For further questions you can contact me any time.
06/08/2016 at 7:07 pm
Hi, you posted this a long time ago so I’m not sure if you’ll respond. I’m dabbling in R for the first time and am trying to create a 3d plot like this. Could you break down your code further? Where do I reference my csv file?
01/10/2011 at 5:59 pm
[…] had mentioned the ideas of geographer Torsten Hägerstrand mapping location against time (see https://geolabs.wordpress.com/2010/11/30/hagerstrand-timespacecube/ for an example). In the digital age Hägerstrand’s map would need a new axis – location in […]
05/05/2014 at 3:34 pm
Hi,
thanks a lot for this nice plot! I was wondering if it was possible to add a shape file at the “bottom” of the cube to delineate cities?
More generally, are they any examples of this plot3d customization? Like plotting arrows despite of lines, giving a weight to individuals, etc?
Thanks a lot for your answer,
Marion
03/16/2016 at 1:03 pm
You could add the outlines/shape of your city as points to the gps dataset and set their date/time to zero respectively to the first timedate of your dataset. You could just alternatively add the points/lines of your city by an additional plot3d command. In both cases, the city shape has to be somehow converted into points or lines that can be interpreted by the plot3d command. Alternatively just add the city map with Photoshop afterwards.
01/31/2017 at 11:13 am
Thanks for this! How did you get the labels for the point locations on the map?
12/08/2018 at 6:16 pm
I added most of the code to the post. I don’t remember, but somewhere in there must be the script for the labels…