suppressPackageStartupMessages(library(knitr))
opts_chunk$set(echo=TRUE, warning=TRUE, message=TRUE, cache=FALSE, fig.align="center")
opts_knit$set(progress=TRUE, verbose=TRUE)

Preamble

This document is an R vignette available under the CC BY-SA 4.0 license.

It is part of the R package UrbanTempo (free software):

library(UrbanTempo)

For more details about free software, you can refer to the information provided by the Free Software Foundation.

The R chunk below is used to assess how much time it takes to execute the R code in this document (see the appendix at the end):

t0 <- proc.time()

Context

Beyond the long-term processes of urbanization, daily urban practices contribute greatly to the production and continual adaptation of the urban fabric. Methodologically, such an investigation can be carried out by means of Lefebvre’s "rhythmanalysis" (original in French in 1992, English translation in 2004), which seeks to capture the everyday rhythms and dynamics of social life. This methodology, initiated in Ho Chi Minh City in Gibert's PhD thesis (2014) and developed in Gibert-Flutre (in prep) as part of the SEANNET program, is particularly relevant in urban context, where it reveals highly polyrhythmic places and neighborhoods.

Reproduce the figure from Gibert's PhD thesis (2014)

Retrieve the data from the example file which is part of the UrbanTempo package (also downloadable online):

f1 <- system.file("extdata", "Gibert_2014_data-PhD-thesis.tsv",
                  package="UrbanTempo")

Load the data from this file (observations from 7am to 12pm):

tpr <- readTemporalities(file=f1)

Retrieve the colors from the example file which is also part of the UrbanTempo package:

f2 <- system.file("extdata", "Gibert_2014_colors-PhD-thesis.tsv",
                  package="UrbanTempo")

Load the colors from this file:

app <- readAppearances(file=f2)

Make the plot:

plotTemporalities(temporalities=tpr, appearances=app,
                  main="Urban temporalities (alleyway 246 Xo Viet Nghe Tinh)",
                  data.source="M. Gibert, 08/08/2011")

Save the plot and the legend together on a two-page PDF file:

pdf(file="plot_temporalities.pdf", width=7, height=4,
    title="Urban temporalities")
plotTemporalities(temporalities=tpr,
                  appearances=app,
                  main="Urban temporalities (alleyway 246 Xo Viet Nghe Tinh)",
                  data.source="M. Gibert, 08/08/2011")
plotLegend(appearances=app)
dev.off()

The resulting PDF file can be edited with Inkscape (free software) or Adobe Illustrator.

Experiment with fake data

Create data

Let's create a minimal data set of two space types, with a total of one interval and two ponctual events over two hours, and save it into a file:

tmpd <- tempdir() # temporary directory
input.df <- data.frame("date"=c("2017-04-23", "2017-04-23", "2017-04-23"),
                       "time"=c("07:24", "07:13", "08:17"),
                       "shops"=c("shop=end", "shop=start", NA),
                       "street"=c("hawker", NA, "hawker"),
                       stringsAsFactors=FALSE)
tmpf <- paste0(tmpd, "/input_temporalities.tsv") # temporary file
write.table(x=input.df, file=tmpf, quote=FALSE, sep="\t",
            row.names=FALSE, col.names=TRUE)

Load data

Such a file can be loaded with the following function, whose output is here assigned to a variable named tpr:

tpr <- readTemporalities(file=tmpf, duration.event=60, verbose=1)

More details are available in the help of this function, via ?readTemporalities.

The set of unique temporality types per space type can be obtained via the following command:

lapply(tpr, function(x){unique(x$id)})

Plot data

First, we need to specify the appearance of each type of temporalities, such as their colors which can be chosen via a palette:

app <- list("shops"=data.frame(color="chocolate", row.names="shop"),
            "street"=data.frame(color="blueviolet", row.names="hawker"))

Then, the input temporalities contained in the tpr variable can be plotted with the following function:

plotTemporalities(temporalities=tpr, appearances=app,
                  main="Fake example of urban temporalities",
                  data.source="fake example, 2017",
                  vertical.bars.per.hour=TRUE,
                  verbose=1)

More details are available in the help of this function, via ?plotTemporalities.

To add the legend, look at the ?plotLegend function:

plotLegend(appearances=app)

Clean

Remove the temporary file:

if(file.exists(tmpf))
  file.remove(tmpf)

Appendix

Below are some details about this vignette:

t1 <- proc.time()
t1 - t0
print(sessionInfo(), locale=FALSE)


marieflutre/UrbanTempo documentation built on June 14, 2019, 4:06 p.m.