class: center, middle, inverse, title-slide #
Calendar-based Graphics
for
Visualising People’s Daily Schedules ### Earo Wang
Monash University ### Dec 11, 2017 --- class: middle center background-image: url(img/sensor.png) background-size: 55% # .blue[Melbourne pedestrian activity] --- .left-column[ ## Pedestrian counting system ### - sensors ] .right-column[ ## The city of Melbourne <img src="figure/sensor-map-1.svg" style="display: block; margin: auto;" /> ] --- .left-column[ ## Pedestrian counting system ### - sensors ### - the data ] .right-column[ * Sourced from [Melbourne open data portal](http://www.pedestrian.melbourne.vic.gov.au) * Access the pedestrian data through the [rwalkr](http://pkg.earo.me/rwalkr/) package * Up-to-date data till 2017-12-09 ``` #> # A tibble: 378,024 x 6 #> Sensor Date_Time Date #> <chr> <dttm> <date> #> 1 Alfred Place 2017-01-01 2017-01-01 #> 2 Australia on Collins 2017-01-01 2017-01-01 #> 3 Birrarung Marr 2017-01-01 2017-01-01 #> 4 Bourke St-Russell St (West) 2017-01-01 2017-01-01 #> 5 Bourke Street Mall (North) 2017-01-01 2017-01-01 #> 6 Bourke Street Mall (South) 2017-01-01 2017-01-01 #> 7 Chinatown-Lt Bourke St (South) 2017-01-01 2017-01-01 #> 8 Chinatown-Swanston St (North) 2017-01-01 2017-01-01 #> 9 City Square 2017-01-01 2017-01-01 #> 10 Collins Place (North) 2017-01-01 2017-01-01 #> # ... with 378,014 more rows, and 3 more variables: #> # Time <int>, Count <int>, Holiday <lgl> ``` ] --- .left-column[ ## Take a glimpse ### - selected sensors ] .right-column[ * Southbank * Southern Cross Station * Victoria Market <img src="figure/selected-sensor-1.svg" style="display: block; margin: auto;" /> ] --- .left-column[ ## Take a glimpse ### - selected sensors ### - time series plot ] .right-column[ <img src="figure/ts-plot-1.svg" style="display: block; margin: auto;" /> ] --- .left-column[ ## Take a glimpse ### - selected sensors ### - time series plot ### - faceted display ] .right-column[ <img src="figure/facet-time-1.svg" style="display: block; margin: auto;" /> ] --- background-image: url(img/calendar.png) background-size: cover --- background-image: url(figure/sx-hol-1.svg) background-size: cover --- class: inverse middle center <img src="img/sugrrants.svg" height=200px size=50%> ##
calendar-based visualisation --- .left-column[ ## Calendar-based vis ### - construction ] .right-column[ <center> <img src="img/month.png" width = 500> </center> The grid position for any day in the month is given by `$$\begin{align} i &= \lceil (g \mod 35) / 7\rceil \\ j &= g \mod 7. \end{align}$$` Let `\(h\)` and `\(c\)` be the scaled hour and count, respectively, then the final coordinates are given by: `$$\begin{align} x &= j + h \\ y &= i - c. \end{align}$$` ] --- .left-column[ ## Calendar-based vis ### - construction ### - the args ] .right-column[ ### The `frame_calendar()` function ```r frame_calendar( data, x, y, date, calendar = "monthly", dir = "h", sunday = FALSE, nrow = NULL, ncol = NULL, polar = FALSE, scale = "fixed", width = 0.95, height = 0.95 ) ``` * `x`, `y`: a unquoted (or bare) variable mapping to x and y axis. * `date`: a Date variable mapping to dates in the calendar. * `calendar`: type of calendar. "monthly", "weekly", "daily". * `sunday`: `FALSE` indicating to starting with Monday in a week, or `TRUE` for Sunday. * `nrow`, `ncol`: number of rows and columns defined for "monthly" calendar layout. * `scale`: "fixed", "free", "free_wday", and "free_mday". ] --- .left-column[ ## Calendar-based vis ### - construction ### - the args ### - usage ] .right-column[ ## Rearrange the data ```r sx_cal <- pedestrian %>% filter(Sensor == "Southern Cross Station") %>% * frame_calendar(x = Time, y = Count, date = Date) ``` ``` #> # A tibble: 8,232 x 5 #> Time Count Date .Time .Count #> * <int> <int> <date> <dbl> <dbl> #> 1 0 1335 2017-01-01 0.2583333 0.9860202 #> 2 1 463 2017-01-01 0.2598631 0.9721692 #> 3 2 219 2017-01-01 0.2613929 0.9682934 #> 4 3 122 2017-01-01 0.2629227 0.9667527 #> 5 4 21 2017-01-01 0.2644525 0.9651484 #> 6 5 28 2017-01-01 0.2659823 0.9652596 #> 7 6 26 2017-01-01 0.2675121 0.9652278 #> 8 7 35 2017-01-01 0.2690419 0.9653708 #> 9 8 55 2017-01-01 0.2705717 0.9656884 #> 10 9 82 2017-01-01 0.2721014 0.9661173 #> # ... with 8,222 more rows ``` ] --- .left-column[ ## Calendar-based vis ### - construction ### - the args ### - usage ] .right-column[ ## Initialise the plot with `ggplot2` ```r p1_sx <- sx_cal %>% ggplot(aes(x = .Time, y = .Count, group = Date)) + geom_line() ``` <img src="figure/sx-plot-1.svg" style="display: block; margin: auto;" /> ] --- .left-column[ ## Calendar-based vis ### - construction ### - the args ### - usage ] .right-column[ ## Add reference lines and labels ```r prettify(p1_sx) ``` <img src="figure/sx-prettify-1.svg" style="display: block; margin: auto;" /> ] --- .left-column[ ## Calendar-based vis ### - construction ### - the args ### - usage ] .right-column[ ## Colour mapping as usual ```r p2_sx <- sx_cal %>% ggplot(aes(x = .Time, y = .Count, colour = Holiday, group = Date)) + geom_line() prettify(p2_sx) ``` <img src="figure/sx-hol-1.svg" style="display: block; margin: auto;" /> ] --- .left-column[ ## Calendar-based vis ### - construction ### - the args ### - usage ] .right-column[ ## Zoom in to March <img src="figure/sx-march-1.svg" style="display: block; margin: auto;" /> ] --- .left-column[ ## Calendar-based vis ### - construction ### - the args ### - usage ] .right-column[ ## Naturally work with the `group_by()` ```r facet_cal <- subdat %>% group_by(Sensor) %>% * frame_calendar( * x = Time, y = Count, date = Date, nrow = 2 * ) p_facet <- facet_cal %>% ggplot(aes(x = .Time, y = .Count, group = Date)) + geom_line(aes(colour = Sensor)) + facet_grid(Sensor ~ .) + scale_colour_brewer(palette = "Dark2") prettify(p_facet, label = NULL) ``` ] --- .left-column[ ## Calendar-based vis ### - construction ### - the args ### - usage ] .right-column[ ## Faceted calendar plots <img src="figure/facet-1.svg" style="display: block; margin: auto;" /> ] --- ##
Summary * The full range of plotting capabilities in *ggplot2* is essentially available, from `geom_point()` to `geom_boxplot()`. * Other language supports are made for month and weekday labels, like CJK. * Patterns on special events for the region, like Anzac Day in Australia, or Thanksgiving Day in the USA, more easily pop out to the viewer as public holidays. * This sort of layout will be useful for studying consumer trends, or human behavior, such as pedestrian patterns or residential electricity demand. --- class: inverse middle center # Joint work with [Di Cook](http://dicook.org) and [Rob J Hyndman](http://robjhyndman.com) # Made with [
]() and
# Questions