suppressPackageStartupMessages(library(knitr)) opts_chunk$set(echo=TRUE, warning=TRUE, message=TRUE, cache=FALSE, fig.align="center") opts_knit$set(progress=TRUE, verbose=TRUE)
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()
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.
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.
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)
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)})
First, we need to specify the appearance of each type of temporalities, such as their colors which can be chosen via a palette:
http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf
https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/colorPaletteCheatsheet.pdf
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)
Remove the temporary file:
if(file.exists(tmpf)) file.remove(tmpf)
Below are some details about this vignette:
t1 <- proc.time() t1 - t0 print(sessionInfo(), locale=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.