1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
\documentclass[a4paper, 11pt, landscape]{article}
% \usepackage{crla_titlepage}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{pdflscape}
\usepackage[total={10in, 7in}]{geometry}
\author{Benjamin Chausse}
\date{\today}
\title{Climbers Over Time at La Débarque}
% \personaltitle{}
% \classnb{}
% \subject{}
% \group{}
% \teacher{}
\begin{document}
\maketitle
\newpage
<<LIBRARIES>>=
library(ggplot2)
library(ggforce)
library(scales)
@
<<CSV>>=
attendance <- data.frame(
read.csv("./debarque.csv",
header=TRUE,
sep=","))
attendance$DAY <- as.POSIXct(attendance$DAY,format="%Y-%m-%d")
attendance$TIME <- as.POSIXct(attendance$TIME,format="%R")
attendance$WEEKDAY <- weekdays(attendance$DAY)
attendance$WEEKDAY <- factor(attendance$WEEKDAY,
levels=c(
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"))
@
\newpage
<<WEEK-PLOT>>=
# Day of the week averages
week <- ggplot(attendance,
aes(x=TIME,
y=CLIMBERS,
group=WEEKDAY,
col=as.factor(DAY))) +
geom_path(group=attendance$DAY) +
geom_smooth(method="gam") +
scale_y_continuous(
breaks=seq(1,25,2),
limits=c(0,25),
labels = scales::number_format(accuracy = 1)) +
scale_x_datetime(
labels=date_format("%R", tz="America/Toronto"),
date_breaks="2 hours") +
labs(x="Time of day",
y="Number of climbers") +
theme(legend.position="none") +
facet_wrap(~WEEKDAY)
@
<<TIMELINE-PLOT>>=
# Daily attendances through time
timeline <- ggplot(attendance, aes(x=DAY, y=CLIMBERS)) +
geom_line(stat="summary", fun=mean)
@
\centering
<<PRINT-WEEK, echo=FALSE, fig.fullwidth=TRUE, fig.width=10>>=
print(week)
@
% <<PRINT-TIMELINE, fig.width=10, fig.fullwidth=TRUE, echo=FALSE>>=
% print(timeline)
% @
\end{document}
|