Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library(ggmap)
library(ggplot2)
library(ggthemes)
library(dplyr)
require(data.table)
print("read GTFS data started")
# use fread for increased speed (~1GB shapes.txt)
shapes <- fread("[shapes_path]/shapes.txt", sep =",", encoding ="UTF-8")
print("read GTFS data finished")
print ("start map fetch")
lx_map <- get_stamenmap(bbox = c(left=2.8, bottom=53.95, right=32.26, top=71.53), source ="stamen", maptype = "toner-lite",color = "bw" ,scale = 2, zoom = 7)
print ("finished map fetch")
# plot the map with a line for each group of shapes (route). Had some scaling issues - work-around: use aspect.ratio 1.6
print ("start map plotting")
plotted_map <-
ggsave(filename = "pt_map.png",
ggmap(lx_map, darken = 1) +
geom_path(data = shapes,
aes(shape_pt_lon, shape_pt_lat, group = shape_id),
size = .1,
alpha = .5,
color='red') +
theme(aspect.ratio=1.6, axis.line=element_blank(),axis.text.x=element_blank(),
axis.text.y=element_blank(),axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),legend.position="none",
panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),plot.background=element_blank()),
device = "png",
path = "[image_path]",
height = 7,
width = 7
)
print ("finished map plotting")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment