Created
August 30, 2015 14:20
-
-
Save patperu/dadcd221e2bc6d63ad2d to your computer and use it in GitHub Desktop.
AMAT GTFS Palermo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Initial code: http://jkunst.com/r/plotting-gtfs-data-with-r/ | |
| # GTFS source | |
| # http://www.comune.palermo.it/opendata_dld.php?id=318 | |
| library("dplyr") | |
| library("readr") | |
| library("ggplot2") | |
| library("ggthemes") | |
| options(stringsAsFactors = FALSE) | |
| shapes <- read.csv("data/gtfs/shapes.txt") | |
| head(shapes) | |
| p <- ggplot(shapes) + | |
| geom_path(aes(shape_pt_lon, shape_pt_lat, group = shape_id), | |
| size = .1, alpha = .1) + | |
| coord_equal() + | |
| theme_map() | |
| p | |
| routes <- read_csv("data/gtfs/routes.txt") | |
| trips <- read.csv("data/gtfs/trips.txt") | |
| stops <- read.csv("data/gtfs/stops.txt") | |
| # stops_metro <- stops %>% | |
| # filter(!grepl("\\d", stop_id)) | |
| stops_metro <- stops | |
| # routes_metro <- routes %>% | |
| # filter(grepl("^L\\d", route_id)) | |
| routes_metro <- routes | |
| shapes_metro <- shapes %>% | |
| filter(shape_id %in% trips$shape_id[trips$route_id %in% routes_metro$route_id]) %>% | |
| arrange(shape_id, shape_pt_sequence) | |
| shapes_colors <- left_join(left_join(shapes %>% select(shape_id) %>% unique(), | |
| trips %>% select(shape_id, route_id) %>% unique(), | |
| by = "shape_id"), | |
| routes %>% select(route_id, route_color) %>% unique(), | |
| by = "route_id") %>% | |
| mutate(route_color = paste0("#", route_color)) | |
| shapes_colors_metro <- shapes_colors %>% | |
| filter(shape_id %in% trips$shape_id[trips$route_id %in% routes_metro$route_id]) %>% unique() %>% | |
| arrange(shape_id) | |
| p2 <- ggplot() + | |
| geom_path(data = shapes, | |
| aes(shape_pt_lon, shape_pt_lat, group = shape_id), | |
| color = "white", size = .2, alpha = .05) + | |
| geom_path(data = shapes_metro, | |
| aes(shape_pt_lon, shape_pt_lat, group = shape_id, colour = shape_id), | |
| size = 1, alpha = .7) + | |
| scale_color_manual(values = shapes_colors_metro$route_color) + | |
| geom_point(data = stops_metro, | |
| aes(stop_lon, stop_lat), shape = 21, colour = "white", alpha = .8, size = 0.5) + | |
| coord_equal() + | |
| theme_map() + | |
| theme(plot.background = element_rect(fill = "black", colour = "black"), | |
| title = element_text(hjust = 1, colour = "white", size = 8), | |
| axis.title.x = element_text(hjust = 0, colour = "white", size = 7), | |
| legend.position = "none") + | |
| xlab(sprintf("Joshua Kunst | Jkunst.com %s", format(Sys.Date(), "%Y"))) + | |
| ggtitle("AMAT\nPalermo's public transport system\n Initial code: http://jkunst.com/r/plotting-gtfs-data-with-r/") | |
| p2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment