library(dplyr)
library(ggplot2)
library(ggmap)
library(jsonlite)
# To be able read cyrillic chars from dataset
Sys.setlocale('LC_ALL', 'Ukrainian')
## [1] "LC_COLLATE=Ukrainian_Ukraine.1251;LC_CTYPE=Ukrainian_Ukraine.1251;LC_MONETARY=Ukrainian_Ukraine.1251;LC_NUMERIC=C;LC_TIME=Ukrainian_Ukraine.1251"
Near UCU campus on Kozelnytska str there are three bus stops. This dataset is a crowled GPS data for buses, which stops there. You can download latest dataset from this repository
bus_stops <- fromJSON("bus_stops.json", flatten=T)
bus_stops <- bus_stops[,-c(6,7)]
map <- qmap('Lviv', zoom = 16, maptype = 'hybrid', location = c(lon = 24.02581, lat = 49.81666))
map + geom_point(data = bus_stops, aes(x = X, y = Y), color=bus_stops$Id, size=5, alpha=1)
data <- read.csv("busdata_200717_1730.csv", encoding="UTF-8")
data$datetime <- as.character(data$datetime)
data$datetime <- as.POSIXct(strptime(data$datetime, "%Y-%m-%d %H:%M:%OS", tz="GMT"))
colnames(data)[14] <- "longitude"
colnames(data)[15] <- "latitude"
data = data[,-c(3, 4,5,6,8)]
dim(data)
## [1] 92495 11
summary(data)
## datetime angle routeid
## Min. :2017-07-18 19:24:26 Min. :-179.944 Min. : 712988
## 1st Qu.:2017-07-19 10:36:27 1st Qu.: -10.969 1st Qu.: 712991
## Median :2017-07-19 17:38:07 Median : 0.000 Median : 713002
## Mean :2017-07-19 20:22:28 Mean : 7.743 Mean :1079607
## 3rd Qu.:2017-07-20 07:44:32 3rd Qu.: 16.241 3rd Qu.:1723724
## Max. :2017-07-20 14:10:39 Max. : 180.000 Max. :1723724
## NA's :4372 NA's :4372
## startpoint state timetopoint vehicleid
## Mode:logical Min. :0.000 Min. :-8427.0 Min. :37158
## NA's:92495 1st Qu.:1.000 1st Qu.: 0.0 1st Qu.:37984
## Median :1.000 Median : 439.0 Median :38934
## Mean :0.973 Mean : 710.1 Mean :44416
## 3rd Qu.:1.000 3rd Qu.: 1623.0 3rd Qu.:47976
## Max. :3.000 Max. :11944.0 Max. :64507
## NA's :4372 NA's :4372 NA's :4372
## vehiclename longitude latitude lowfloor
## : 4372 Min. : 0.00 Min. : 0.00 : 4372
## ВС 2801 АА: 1548 1st Qu.:23.97 1st Qu.:49.80 f:64190
## ВС 2615 ЕВ: 1537 Median :24.02 Median :49.81 t:23933
## ВС 7284 СО: 1525 Mean :20.20 Mean :41.91
## ВС 2498 ЕТ: 1523 3rd Qu.:24.05 3rd Qu.:49.84
## ВС 9144 ВТ: 1514 Max. :24.08 Max. :49.92
## (Other) :80476 NA's :4372 NA's :4372
So there are over 90000 records of 8 different bus routes (68 different vehicles).
head(data)
## datetime angle routeid startpoint state timetopoint
## 1 2017-07-18 19:24:26 0.0000 712988 NA 2 -3412
## 2 2017-07-18 19:24:26 108.7117 712988 NA 1 10027
## 3 2017-07-18 19:24:26 0.0000 712988 NA 0 0
## 4 2017-07-18 19:24:27 0.0000 712988 NA 0 0
## 5 2017-07-18 19:24:27 0.0000 712988 NA 2 -1484
## 6 2017-07-18 19:24:27 0.0000 712988 NA 0 3099
## vehicleid vehiclename longitude latitude lowfloor
## 1 38682 ВС 3164 АА 24.00013 49.83512 f
## 2 38687 ВС 3162 АА 23.96624 49.84706 f
## 3 38689 ВС 3170 АА 0.00000 0.00000 f
## 4 38695 ВС 0801 АА 0.00000 0.00000 f
## 5 38702 ВС 1121 АА 23.99891 49.83544 f
## 6 38704 ВС 1182 АА 23.99981 49.83535 f
Lets visualize this data on Lviv map
map <- qmap('Lviv', zoom = 12, maptype = 'hybrid')
map + geom_point(data = data, aes(x = longitude, y = latitude), color=data$vehicleid, size=3, alpha=0.25)