R combined gps-track plot of spatial intensity
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
To get a quick impression about the temporal stay of places it is helpful to generate a plot of the trackpoints spatial density (intensity).
As the 3d visualisation has both advatages and disadvantages, a combination with a 2D plot is useful to interpret the data. The data used in this example is a gps record of the “everyday life” of a test person.
Code snippet:
###################################################
## 3d/2D Plot density with spatstat density.ppp
###################################################
bb_utm <- qbbox(lat = tripdata_utm_num[,2], lon = tripdata_utm_num[,1]) #Boundingbox
Rect <- owin(c(bb_utm$lonR[1]-500, bb_utm$lonR[2]+1800), c(bb_utm$latR[1]-500, bb_utm$latR[2]+500))
P_all <- ppp(tripdata_utm_num[,1], tripdata_utm_num[,2], window=Rect) # opt: marks=datetime
PPP_all <- as.ppp(P_all)
den <- density(PPP_all, sigma = 70)
cutted_den <- den # Wertebereich abschneiden für Extreme
cutvalue <- 0.0020 # Erfahrungswert
cutted_den$v[cutted_den$v>=cutvalue] <-cutvalue
png(paste(plotpath,proband,”intensity_overview_spatstat_v3.png”, sep=””),2400,1200); # Plot Dichte 3D
layout(matrix(c(1,2), 2, 2, byrow = TRUE), widths=c(1,1))
persp(cutted_den , col=”grey”, d=1, ticktype=”detailed”, cex.lab=4, cex.axis=4, zlim=c(range(cutted_den$v)[1],cutvalue), phi=30, theta=-20, xlab=”longitude”, ylab=”latitude”, zlab=”density”, main=paste(proband, “Räumliche Intensität”))
couleurs <- tail(topo.colors(trunc(1.4 * 100)),100)
couleurs[1] <- “#0400ff”
plot(cutted_den , col=couleurs, ticktype=”detailed”, xlab=”longitude”, ylab=”latitude”, cex.lab=5, cex.axis=5, main=paste(proband, “Räumliche Intensität 2D”))
#points(SP_UTM@coords[,1], SP_UTM@coords[,2], cex=0.05, col=”grey”)
points(SP_wp_UTM@coords[,1], SP_wp_UTM@coords[,2], cex=2, col=”red”)
text(SP_wp_UTM@coords[,1], SP_wp_UTM@coords[,2], labels=daten_wp$wpOpen, cex=1, adj=c(0,-1), col=”red”)
dev.off()
# If you use any code, please refer to or cite this site (see about geolabs)
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.