GPS 3D visualization
rgl package for 3D plotting
The sample route on Google map
I use the same data that I posted before. The sample test route looks like a square as follows:
However, it is a 2d plot; it does not show the altitude information. The reason why I choose this route is that the course has turns, flat road, and inclined path at the same time.
To show this, I decide to use rgl R package which can draw the 3D plot of GPS path.
mytelematics <- read.csv("https://raw.githubusercontent.com/issactoast/theissacleedotcom/master/static/data/sampletrip.csv", header = TRUE, fill = TRUE) gps_data <- subset(mytelematics, select = c(Timestamp, Long, Lat, Alt.m.)) colnames(gps_data) <- c("Timestamp", "x", "y", "z")
GPS data includes location information such as longitude, latitude, and altitude at each time step.
Route in 3D space
rgl R package is a useful tool for visualizing 3D data. To draw the graph, we need to open a pallet as like
par() in the base plot as follows:
library(rgl) open3d() >> glX >> 1 mfrow3d(1, 1, sharedMouse = TRUE)
If you want to draw multiple 3d plots, you can adjust
mfrow3d just like
mfrow in the base plot. Plotting is also very straight forward; the same syntax but adds the suffix
3d to the
plot3d(gps_data[,2:4], col = "red", size = 5, type = "l")
The generated plot is 3d and also you can rotate the object using your mouse; drag it! Note, this function is not available in the mobile environment.
As we can see, the route looks like a square from the top, but we can see that it has uphill and down-hill from the side. If you magnify it, we can see the beginning, and the endpoint of the route does not match, which I conclude that the GPS altitude information is not that accurate than the latitude and longitude information.
Do not forget to clear the plot after drawing the plot.
For more information, you should check out the vignettes: