Dataset Colleted By: Jing Yuan, Yu Zheng, Xing Xie, Guang Sun, 2011
- Load the R mapping module
- Load the data
- Name the columns
- Review the data structure
library(RgoogleMaps)
setwd("F:/_rdev/telematics/01")
dat <- read.table("366.txt",header=FALSE,sep=",")
colnames(dat) <- c("ID","DateTime","Longitude","Latitude")
str(dat)
## 'data.frame': 99494 obs. of 4 variables:
## $ ID : int 366 366 366 366 366 366 366 366 366 366 ...
## $ DateTime : Factor w/ 95475 levels "2008-02-02 13:30:48",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ Longitude: num 116 116 116 116 116 ...
## $ Latitude : num 39.9 39.9 39.9 39.9 39.9 ...
- Prepare mapping parameters
- Place lat/long coordinates in vectors
center = c(mean(dat$Latitude), mean(dat$Longitude));
zoom <- 15
markers = paste0("&markers=color:Red|label:T|dat$Latitude,dat$Longitude")
# collect coordinates
vlat <- c(); vlat <- dat$Latitude
vlon <- c(); vlon <- dat$Longitude
# Map the coordinates
Taxi366Map <- GetMap(center=center,
zoom=zoom,
markers=paste0("&markers=color:green|label:T|","39.90732,116.4535"),
destfile="Taxi336.png",
maptype="hybrid")
tmp <- PlotOnStaticMap(Taxi366Map,
lat=vlat,lon=vlon,
destfile="Taxi336.png",
cex=0.5,pch=20,col='green',add=FALSE)

Basemap: Hybrid Satellite & Roadways
dat <- read.table("1131.txt",header=FALSE,sep=",")
colnames(dat) <- c("ID","DateTime","Longitude","Latitude")
center = c(mean(dat$Latitude), mean(dat$Longitude));
zoom <- 15
markers = paste0("&markers=color:Red|label:T|",c(mean(dat$Latitude), mean(dat$Longitude)))
# collect coordinates
vlat <- c(); vlat <- dat$Latitude
vlon <- c(); vlon <- dat$Longitude
# Map the coordinates
Taxi1131Map <- GetMap(center=center,
zoom=zoom,
markers=markers,
destfile="Taxi1131.png",
maptype="terrain")
tmp <- PlotOnStaticMap(Taxi1131Map,
lat=vlat,lon=vlon,
destfile="Taxi1131.png",
cex=0.5,pch=20,col='blue',add=FALSE)

Basemap: Terrain
dat <- read.table("1277.txt",header=FALSE,sep=",")
colnames(dat) <- c("ID","DateTime","Longitude","Latitude")
center = c(mean(dat$Latitude), mean(dat$Longitude));
zoom <- 10
markers = paste0("&markers=color:Red|label:T|",c(mean(dat$Latitude), mean(dat$Longitude)))
# collect coordinates
vlat <- c(); vlat <- dat$Latitude
vlon <- c(); vlon <- dat$Longitude
# Map the coordinates
Taxi1277Map <- GetMap(center=center,
zoom=zoom,
markers=markers,
destfile="Taxi1277.png",
maptype="roadmap")
tmp <- PlotOnStaticMap(Taxi1277Map,
lat=vlat,lon=vlon,
destfile="Taxi1277.png",
cex=0.25,pch=20,col='red',add=FALSE)

Basemap: Roadmap