Code
library(dplyr)
library(plot3D)
To make spacetime lines we need 3D plotting capability, for which I used plot3D
and plotly
.
I also jerry-rigged a simple CSV file format, which looks like the dataframe below.
x | y | t |
---|---|---|
5 | 5 | 0.00 |
5 | 5 | 7.50 |
16 | 20 | 8.25 |
16 | 20 | 12.50 |
14 | 18 | 12.60 |
14 | 18 | 13.40 |
Not tremendously interesting, but you can imagine additional attributes describing what each \((x,y,t)\) triple is and before you know it you’ll be dealing in geotemporal atoms, although… the instantaneity implied in this representation would be rather questionable. However, the point here isn’t to invent a geotemporal information system, just to make some spacetime plots, so…
The plot3D
functions aren’t the most straightforward to use, but after some experimentation I came up with the following two pictures. First… a classic ‘day in the life’ plot.
lines3D(time_space_data$x, time_space_data$y, time_space_data$t,
xlim = c(min(time_space_data$x) - 2,
max(time_space_data$x) + 2),
ylim = c(min(time_space_data$y) - 2,
max(time_space_data$y) + 2),
xlab = "x", ylab = "y", zlab = "Time, t",
col = "#00000080", lwd = 2, alpha = 0.5,
phi = 25, theta = 60, bty = "g", scale = FALSE)
points3D(locations_0$x, locations_0$y, locations_0$t,
add = TRUE, col = "black")
arrows3D(locations_0$x, locations_0$y, locations_0$t,
locations_24$x, locations_24$y, locations_24$t,
add = TRUE, lty = "dashed", lwd = 0.5, col = "black")
And second, a ‘meeting’ plot, where a collection of meeting participants converge into a ‘bundle’ in one place over a period of time.
time_space_data <- read.csv("tg-meeting.csv")
trace <- time_space_data |>
filter(id == 1)
lines3D(trace$x, trace$y, trace$t,
xlim = c(-6, 6), ylim = c(-6, 6),
xlab = "x", ylab = "y", zlab = "Time, t",
col = "black", lwd = 1, phi = 25, theta = 60,
bty = "g", scale = FALSE)
for (i in 2:8) {
trace <- time_space_data |> filter(id == i)
lines3D(trace$x, trace$y, trace$t, add = TRUE,
xlim = c(-6, 6), ylim = c(-6, 6),
col = "black", lwd = 1)
}
# License (MIT)
#
# Copyright (c) 2023 David O'Sullivan
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
© 2023-24 David O’Sullivan