# NOT RUN {
library(dplyr, warn.conflicts = FALSE)
# compute the calendar layout for the data frame
calendar_df <- pedestrian %>%
filter(Sensor_ID == 13, Year == 2016) %>%
frame_calendar(x = Time, y = Hourly_Counts, date = Date, nrow = 4)
# ggplot
p1 <- calendar_df %>%
ggplot(aes(x = .Time, y = .Hourly_Counts, group = Date)) +
geom_line()
prettify(p1, size = 3, label.padding = unit(0.15, "lines"))
# use in conjunction with group_by()
grped_calendar <- pedestrian %>%
filter(Year == "2017", Month == "March") %>%
group_by(Sensor_Name) %>%
frame_calendar(x = Time, y = Hourly_Counts, date = Date, week_start = 7)
p2 <- grped_calendar %>%
ggplot(aes(x = .Time, y = .Hourly_Counts, group = Date)) +
geom_line() +
facet_wrap(~ Sensor_Name, nrow = 2)
prettify(p2)
# }
# NOT RUN {
# allow for different languages
# below gives simplied Chinese labels with STKaiti font family,
# assuming this font installed in user's local system
prettify(p2, locale = "zh", family = "STKaiti")
# plotly example
if (!requireNamespace("plotly", quietly = TRUE)) {
stop("Please install the 'plotly' package to run these following examples.")
}
library(plotly)
pp <- calendar_df %>%
group_by(Date) %>%
plot_ly(x = ~ .Time, y = ~ .Hourly_Counts) %>%
add_lines(text = ~ paste("Count: ", Hourly_Counts, "<br> Time: ", Time))
prettify(pp)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab