In [1]:
library(ggplot2)
library(dplyr)
library(ggmap)
library(maps)
library(mapdata)
library(lubridate)
options(jupyter.plot_mimetypes = 'image/png')


Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Google Maps API Terms of Service: http://developers.google.com/maps/terms.
Please cite ggmap if you use it: see citation("ggmap") for details.

Attaching package: ‘lubridate’

The following object is masked from ‘package:base’:

    date


In [2]:
path <- "./google_transit"
data_path <- "./d3js-test/"
extension <- ".txt"

In [3]:
stopEdge_shapePts <- read.csv(file=file.path(path, paste("stopEdge_shapePts", extension, sep="")), header=T)
shape_stopEdge <- read.csv(file=file.path(path, paste("shape_stopEdge", extension, sep="")), header=T)
shapes <- read.csv(file=file.path(path, paste("shapes", extension, sep="")), header=T)
trip_idTOshape_id <- read.csv(file=file.path(path, paste("trip_idTOshape_id", extension, sep="")), header=T)
stop_times <- read.csv(file=file.path(path, paste("stop_times", extension, sep="")), header=T)
stops <- read.csv(file=file.path(path, paste("stops", extension, sep="")), header=T)
stop_edge_table <- read.csv(file=file.path(data_path, paste("stop_edge_table", extension, sep="")), header=T)

In [45]:
shape_id_test =  '202_8_22'
shape_stop_edge_test <- shape_stopEdge[shape_stopEdge$shape_id ==  shape_id_test,]
stop_edge_list_test <- shape_stop_edge_test$stop_edge_id

trip_id_test <- trip_idTOshape_id[trip_idTOshape_id$shape_id == shape_id_test,]$trip_id[[1]]
stops_list_test <- stop_times[stop_times$trip_id == trip_id_test,]
stops_test <- merge(stops_list_test, stops)

In [10]:
stopEdge_shapePts_test <- filter(stopEdge_shapePts, stop_edge_id %in% stop_edge_list_test)

In [13]:
size_bbox <- 0.25
bbox <- make_bbox(lon = stopEdge_shapePts_test$shape_pt_lon, lat = stopEdge_shapePts_test$shape_pt_lat, f = bbox)
sq_map <- get_map(location = bbox, maptype = "roadmap", source = "google")


Warning message:
“bounding box given to google - spatial extent only approximate.”converting bounding box to center/zoom specification. (experimental)
Source : https://maps.googleapis.com/maps/api/staticmap?center=32.87185,-117.2265&zoom=15&size=640x640&scale=2&maptype=roadmap&language=en-EN

In [54]:
stop_edge_test_path_plot <- geom_path(data = stopEdge_shapePts_test,
                                      mapping = aes(x = shape_pt_lon, y = shape_pt_lat, colour=stop_edge_id), 
                                      alpha = 0.9, size = 2, show.legend = F)

stops_test_plot = geom_point(data = stops_test,
                             mapping = aes(x = stop_lon, y = stop_lat), 
                             color="black", alpha = 0.5, size = 5, show.legend = F)

In [55]:
ggmap(sq_map) + stop_edge_test_path_plot + stops_test_plot



In [57]:
shapes_plot <- geom_point(data = shapes,
                           mapping = aes(x = shape_pt_lon, y = shape_pt_lat, colour=shape_id), 
                           alpha = 0.2, size = 2, show.legend = F)

In [58]:
ggmap(sq_map) + shapes_plot + stops_test_plot


Warning message:
“Removed 120722 rows containing missing values (geom_point).”

In [60]:
shapes_test <- shapes[shapes$shape_id == shape_id_test,]
shapes_test_plot <- geom_point(data = shapes_test,
                           mapping = aes(x = shape_pt_lon, y = shape_pt_lat, colour=shape_id), 
                           alpha = 0.9, size = 2, show.legend = F)

In [69]:
ggplot() + shapes_test_plot



In [64]:
stop_edge_test_path_points_plot <- geom_point(data = stopEdge_shapePts_test,
                                              mapping = aes(x = shape_pt_lon, y = shape_pt_lat, colour=stop_edge_id), 
                                              alpha = 0.9, size = 2, show.legend = F)

In [68]:
ggplot() + stop_edge_test_path_points_plot



In [4]:
stop_edge_table <- stop_edge_table[(complete.cases(stop_edge_table)),]

In [7]:
stop_edge_listed <- unique(stop_edge_table$stop_edge_id)


  1. 40076_40206
  2. 50096_99420
  3. 60209_60254
  4. 12785_99069
  5. 10553_12108
  6. 10224_10594

In [8]:
stopEdge_shapePts_listed <- filter(stopEdge_shapePts, stop_edge_id %in% stop_edge_listed)

In [26]:
size_big_bbox <- 0.25
big_bbox <- make_bbox(lon = stopEdge_shapePts_listed$shape_pt_lon, lat = stopEdge_shapePts_listed$shape_pt_lat, f = size_big_bbox)
big_sq_map <- get_map(location = big_bbox, maptype = "roadmap", source = "google")


Warning message:
“bounding box given to google - spatial extent only approximate.”converting bounding box to center/zoom specification. (experimental)
Source : https://maps.googleapis.com/maps/api/staticmap?center=32.8337,-116.9915&zoom=10&size=640x640&scale=2&maptype=roadmap&language=en-EN

In [27]:
stopEdge_shapePts_listed_plot <- geom_point(data = stopEdge_shapePts_listed,
                                            mapping = aes(x = shape_pt_lon, y = shape_pt_lat, colour=stop_edge_id), 
                                            alpha = 0.3, size = 2, show.legend = F)

In [28]:
ggmap(big_sq_map) + stopEdge_shapePts_listed_plot



In [8]:
qplot(stop_edge_table$hour, stop_edge_table$v_avg)



In [5]:
stop_edge_max_entry <- stop_edge_table[stop_edge_table$v_avg == max(stop_edge_table$v_avg),]

In [6]:
stop_edge_max_entry


stop_edge_idhourdowv_avg
4028912995_1299616 5 167.6377
12462510075_1299616 5 167.6377
25129711612_1163816 5 167.6377
29598511612_1238916 5 167.6377
49002510449_1238916 5 167.6377
54076110449_9902616 5 167.6377
61972110454_9902616 5 167.6377
75059312995_6050016 5 167.6377

TODO CHECK THE 992!