Skip to content

Instantly share code, notes, and snippets.

@jfaganUK
Created April 30, 2015 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfaganUK/28857a00137f91abb535 to your computer and use it in GitHub Desktop.
Save jfaganUK/28857a00137f91abb535 to your computer and use it in GitHub Desktop.
Bus tracker
library(XML)
library(data.table)
library(ggplot2)
library(ggmap)
args <- commandArgs(trailingOnly = T)
cat(args)
x <- readLines('http://realtime.lextran.com/InfoPoint/map/GetVehicleXml.ashx?RouteId=3')
xm <- xmlTreeParse(x, useInternalNodes = T)
vs <- getNodeSet(xm, '/vehicles/vehicle')
vehicles <- data.table(lat = as.numeric(sapply(vs, function(v) xmlGetAttr(v, 'lat'))),
long = as.numeric(sapply(vs, function(v) xmlGetAttr(v, 'lng'))),
name = sapply(vs, function(v) xmlGetAttr(v, 'name')))
lexmap <- qmap('Lexington, KY', zoom = 12, source = 'stamen', maptype = 'toner')
g <- lexmap + geom_point(data = vehicles, aes(x=long, y = lat, color = name), size = 10, alpha = 0.8)
png('busplot.png')
print(g)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment