??matsim::process_filter_by_shape
a <- "2.8"
as.integer(a)
library(tidyverse)
library(matsim)
library(devtools)
install.packages("devtools")
install.packages("matsim")
devtools::install_github("matsim-vsp/matsim-r")
library(matsim)
library(leaflet)
library(sf)
trips_data %>% group_by(dep_time_round) %>%
count() %>% #count() counts the number of trips for us
ggplot(aes(x = dep_time_round, y = n)) +
geom_line(size = 1.25) +
xlab("Depature Time") + #Labeling of x-axis
ylab("# Of Trips") + #Labeling of y-axis
theme_minimal() +
theme(legend.position = "bottom", legend.title = element_blank())
#install.packages("pacman")
pacman::p_load(tidyverse, scales, lubridate, ggrepel)
#install.packages("tidyverse", "scales", "lubridate")
library(tidyverse)
library(scales)
library(lubridate)
library(ggrepel)
# Define the URL of the csv.gz file and the destination file path
url <- "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/tutorial/datascience2024/matsim_outputs/output-1pct/base/berlin-v6.3.output_trips.csv.gz"
destfile <- "yourfile.csv.gz"
# Download the file
download.file(url, destfile)
# Get the current working directory (to return later, if needed)
original_dir <- getwd()
# Move to the directory where the file is located
file_dir <- dirname(destfile)
setwd(file_dir)
# Unzip and read the file
trips_data <- read_delim(gzfile(basename(destfile)))
# Print the first few rows of the dataset
head(trips_data)
# We use `glimpse()` for a first impression of the data frame.
glimpse(trips_data)
#We use `head()` to look at the first rows of the data frame.
head(trips_data)
#We use`tail()` to look at the final rows of the data frame.
tail(trips_data)
#We use sample_n(), to sample n rows from the data frame.
sample_n(trips_data, size = 6) # What effect does the size argument have?
trips_data_tidy <- trips_data %>% select(person, dep_time, trav_time, wait_time) %>%
pivot_longer(cols = c("dep_time", "trav_time", "wait_time"), values_to = "Duration", names_to = "Considered_Time")
head(trips_data_tidy)
trips_data <- trips_data %>% select("person", "dep_time", "trav_time", "wait_time", "traveled_distance", "main_mode", "longest_distance_mode", "modes")
trips_data %>% group_by(dep_time_round) %>%
count() %>% #count() counts the number of trips for us
ggplot(aes(x = dep_time_round, y = n)) +
geom_line(size = 1.25) +
xlab("Depature Time") + #Labeling of x-axis
ylab("# Of Trips") + #Labeling of y-axis
theme_minimal() +
theme(legend.position = "bottom", legend.title = element_blank())
trips_data %>% mutate(arrival_time = dep_time + wait_time + trav_time)
trips_data %>% group_by(dep_time_round) %>%
count() %>% #count() counts the number of trips for us
ggplot(aes(x = dep_time_round, y = n)) +
geom_line(size = 1.25) +
xlab("Depature Time") + #Labeling of x-axis
ylab("# Of Trips") + #Labeling of y-axis
theme_minimal() +
theme(legend.position = "bottom", legend.title = element_blank())
trips_data <- trips_data %>% mutate(dep_time_round = hms::round_hms(hms::as_hms(dep_time), secs = 300)) %>%
mutate(trav_time_round = hms::round_hms(hms::as_hms(trav_time), secs = 300)) %>%
mutate(wait_time_round = hms::round_hms(hms::as_hms(wait_time), secs = 300)) %>%
mutate(dep_time = hms(as.character(dep_time))) %>%
mutate(trav_time = hms(as.character(trav_time))) %>%
mutate(wait_time = hms(as.character(wait_time))) %>%
mutate(dep_time_seconds = period_to_seconds(dep_time)) %>%
mutate(wait_time_seconds = period_to_seconds(wait_time))
head(trips_data$wait_time_round)
trips_data %>% group_by(dep_time_round) %>%
count() %>% #count() counts the number of trips for us
ggplot(aes(x = dep_time_round, y = n)) +
geom_line(size = 1.25) +
xlab("Depature Time") + #Labeling of x-axis
ylab("# Of Trips") + #Labeling of y-axis
theme_minimal() +
theme(legend.position = "bottom", legend.title = element_blank())
#As I am using a custom palette, this needs to be defined.
palette <- function() {
c("#FD5091", "#F78104", "#FAAB36", "#249EA0", "#008083", "#005F60")
}
ggplot(trips_data, aes(x=dep_time_seconds)) +
geom_histogram(aes(fill=main_mode)) +
scale_fill_manual(values = palette()) +
theme_minimal() +
xlab("Departure time [Seconds]") + #Labeling x_axis
ylab("Count") #Labeling y_axis(labels=comma)
trips_data %>% filter(wait_time_seconds > 0) %>%  filter(wait_time_seconds < 4000) %>%
ggplot(aes(x = wait_time_seconds)) +
geom_histogram(aes(fill = main_mode)) +
theme_minimal() +
scale_fill_manual(values = palette()) +
ylab("Count") +
theme(legend.position = "bottom") +
theme(text = element_text(size = 30)) +
theme(axis.ticks.x = element_line(),
axis.ticks.y = element_line(),
axis.ticks.length = unit(5, "pt"))
trips_data$main_mode <- factor(trips_data$main_mode, levels = rev(c("car", "ride", "walk", "bike", "pt", "freight", "drt", "av")))
trips_data_piechart <- trips_data %>%
count(main_mode) %>%
mutate(Share = n / sum(n)) %>%
mutate(csum = rev(cumsum(rev(Share))),
pos = Share/2 + lead(csum, 1),
pos = if_else(is.na(pos), Share/2, pos))
ggplot(trips_data_piechart, aes(x= "", y = Share, fill = main_mode)) +
geom_col(width = 1, color = 0) +
coord_polar(theta = "y") +
scale_fill_manual(values = palette()) +
geom_label_repel(data = trips_data_piechart,
aes(y = pos, label = paste0(round(100*Share, 2), "%")),
size = 4.5, nudge_x = 1, show.legend = FALSE) +
guides(fill = guide_legend(title = "Mode")) +
theme_void() +
theme(legend.position = "bottom") +
theme(text = element_text(size = 30)) +
theme(axis.ticks.x = element_line(),
axis.ticks.y = element_line(),
axis.ticks.length = unit(5, "pt"))
trips_data %>%
mutate(dep_time_hour = hour(dep_time)) %>%
group_by(dep_time_hour, main_mode) %>%
count() %>%
ungroup() %>%
group_by(dep_time_hour) %>%
mutate(Share = n / sum(n)) %>%
ggplot(aes(dep_time_hour, Share, color = main_mode)) +
scale_color_manual(values = palette()) +
geom_line(size = 1.5) +
xlab("Departure time [hrs]") +
theme_minimal() +
theme(legend.position = "bottom", legend.title = element_blank()) +
theme(legend.position = "bottom") +
theme(text = element_text(size = 30)) +
theme(axis.ticks.x = element_line(),
axis.ticks.y = element_line(),
axis.ticks.length = unit(5, "pt"))
trips_data %>%
mutate(dep_time_hour = hour(dep_time)) %>%
group_by(dep_time_hour, main_mode) %>%
count() %>%
ungroup() %>%
group_by(dep_time_hour) %>%
mutate(Share = n / sum(n)) %>%
ggplot(aes(dep_time_hour, Share, color = main_mode)) +
scale_color_manual(values = palette()) +
geom_line(size = 1.5) +
xlab("Departure time [hrs]") +
theme_minimal() +
theme(legend.position = "bottom", legend.title = element_blank()) +
theme(legend.position = "bottom") +
theme(text = element_text(size = 30)) +
theme(axis.ticks.x = element_line(),
axis.ticks.y = element_line(),
axis.ticks.length = unit(5, "pt"))
trips_data
glimpse(trips_data)
trips_data %>% mutate(`xxx` = person)
p <- trips_data %>% mutate(`xxx` = person)
glimpse(p)
p <- trips_data %>% mutate(`5` = person)
glimpse(p)
bart <- readr::read_csv('bart_data.csv')
setwd("~/Desktop/lesson-05")
bart <- readr::read_csv('bart_data.csv')
glimpse(bart)
bart_clean <- bart %>% pivot_longer(cols = list(`2000`,`2005`,`2010`,`2015`,`2020`), names_to="year", values_to="boardings")
bart_clean <- bart %>% pivot_longer(cols = c(`2000`,`2005`,`2010`,`2015`,`2020`), names_to="year", values_to="boardings")
bart_clean
glimpse(bart_clean)
bart_clean %>% ggplot(aes(boardings))
bart_clean %>% ggplot(aes(station), boardings)
bart_clean %>% ggplot(aes(Station), boardings)
bart_clean %>% ggplot(aes(Station), boardings, color = year)
bart_clean %>% ggplot(aes(Station), boardings, color = year) +
geom_line(size = 1.5)
geom_line(size = 1.5, y=boardings)
bart_clean %>% ggplot(aes(Station), boardings, color = year) +
geom_line(size = 1.5, y=boardings)
glimpse(bart_clean)
bart_clean |> ggplot(aes(Station, boardings)) + geom_line()
bart_clean |> ggplot(aes(Station, boardings), color=year) + geom_line()
bart_clean |> ggplot(aes(Station, boardings, color=year) + geom_line()
bart_clean |> ggplot(aes(Station, boardings, color=year)) + geom_line()
bart_clean |> ggplot(aes(Station, boardings, group_by(year))) + geom_line()
bart_clean |> ggplot(aes(Station, boardings, group_by(Station))) + geom_line()
bart_clean |> ggplot(aes(Station, boardings, color=year) + geom_line()
bart_clean |> ggplot(aes(Station, boardings, color=year)) + geom_line()
bart_clean |> ggplot(aes(x=Station, y=boardings, group=year)) + geom_line()
bart_clean |> ggplot(aes(x=Station, y=boardings, group=year, color=year)) + geom_line()
library(matsim)
matsim::read_output_trips('berlin-v6.3/012.output_trips.csv.gz')
trips <- matsim::read_output_trips('berlin-v6.3/012.output_trips.csv.gz')
glimpse(trips)
matsim::plot_arrtime_by_act(trips)
p1 <- matsim::plot_arrtime_by_act(trips)
p1
p1
#install.packages("tidyverse")
#devtool::install_github("matsim-vsp/matsim-r")
library(tidyverse)
library(matsim)
trips <- matsim::read_output_trips("berlin-v6.3/012.output_trips.csv.gz")
trips <- matsim::read_output_trips("berlin-v6.3/012.output_trips.csv.gz")
p1 <- matsim::plot_arrtime_by_act(trips)
arr_time <- matsim::plot_arrtime_by_act(trips)
main_mode_dist <- matsim::plot_distance_by_mainmode_barchart()
arr_time <- matsim::plot_arrtime_by_act(trips)
main_mode_dist <- matsim::plot_distance_by_mainmode_barchart(trips)
main_mode_dist <- matsim::plot_distance_by_mainmode_barchart(trips)
p1 <- matsim::plot_arrtime_by_act(trips)
matsim::plot_distance_by_mainmode_barchart(trips)
