Visualising and Analysing Daily Routines
In this take home exercise, I will reveal the daily routines of two selected participants of the city of Engagement, Ohio USA using ViSIElse.
Before we get started, it is important to ensure that the R packages have been installed. If yes, we will load the R packages. If they have yet to be installed, we will install the R packages and load them onto R environment.
The chunk code below will do the trick.
packages = c('tidyverse','knitr','ggdist', 'ggridges',
'ggthemes', 'hrbrthemes',
'ggrepel', 'ggforce','viridis','zoo','chron','lubridate','ViSiElse')
for(p in packages){
if(!require(p, character.only = T)){
install.packages(p)
}
library(p, character.only = T)
}
The code chunk below import “Participants.csv” from the data folder
into R by using read_csv()
of readr
and save it as an tibble data frame called “participant_data”.
travel_data <- read_csv("data/TravelJournal.csv") %>%
mutate(date = as.Date(travelStartTime))
We choose two participants whose participantId is 23 and 188 and see the daily patterns of them. To observe the daily patterns, I change each start time and end time of the travel by using minute.
person1 <- travel_data %>% filter(participantId==23)
person1$starttime <- 60*hour(person1$travelStartTime)+minute(person1$travelStartTime)
person1$endtime <- 60*hour(person1$travelEndTime)+minute(person1$travelEndTime)
person2 <- travel_data %>% filter(participantId==188)
person2$starttime <- 60*hour(person2$travelStartTime)+minute(person2$travelStartTime)
person2$endtime <- 60*hour(person2$travelEndTime)+minute(person2$travelEndTime)
I use pivot_wider
to pivot the original data and display the time in minute with
corresponding event.
routine1 <- routine1 %>%
group_by(purpose) %>%
mutate(row = row_number()) %>%
tidyr::pivot_wider(names_from = purpose, values_from = starttime) %>%
tidyr::pivot_wider(names_from = end, values_from = endtime) %>%
select(-row)
routine2 <- routine2 %>%
group_by(purpose) %>%
mutate(row = row_number()) %>%
tidyr::pivot_wider(names_from = purpose, values_from = starttime) %>%
tidyr::pivot_wider(names_from = end, values_from = endtime) %>%
select(-row)
Then we display the daily patterns of these two participants using visielse().
v1 <- visielse(routine1)
b1 <-ConvertFromViSibook(v1@book)
b1 <- b1[order(as.numeric(b1$showorder)), ]
b1$showorder <- c(1,7,3,8,4,9,5,10,6,2)
b1 <- b1[order(as.numeric(b1$showorder)), ]
v1 <- visielse(routine1,book = b1, informer = NULL, doplot = F, pixel = 30)
plot(v1, vp0w = 0.7, unit.tps = "min", scal.unit.tps = 30, main = "Daily Routine For Participant 23")
v2 <- visielse(routine2)
b2 <-ConvertFromViSibook(v2@book)
b2 <- b2[order(as.numeric(b1$showorder)), ]
b2$showorder <- c(1,7,3,8,4,9,5,10,6,2)
b2 <- b2[order(as.numeric(b1$showorder)), ]
v2 <- visielse(routine2,book = b2, informer = NULL, doplot = F, pixel = 30)
plot(v2, vp0w = 0.7, unit.tps = "min", scal.unit.tps = 30, main = "Daily Routine For Participant 188")