-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
184 lines (130 loc) · 4.88 KB
/
README.Rmd
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(csatimer)
library(ggplot2)
library(tidyverse)
```
# csatimer
`csatimer` provides data on how much airtime French politician receive in the media.
The datasets contained in the package are also [available](https://github.com/benjaminguinaudeau/csatimer/tree/master/inst/csv) in the csv-format.
## Installation
``` r
# install.packages("devtools")
devtools::install_github("benjaminguinaudeau/csatimer")
```
## Data
*Last Update: February, 2nd 2022*
Two types of datasets are provided:
* speaking time of politicians during routine period (no electoral campaigns)
* speaking time of candidates during political campaigns
### Routine period (no electoral campaigns)
Every month, the [CSA](https://www.csa.fr/csapluralisme/tableau) collects how long each political personality speaks on each of the major radio and TV stations.
This dataset can be accessed using `read_csa_routine` and is continuous between September 2017 and January 2022.
```{r}
read_csa_routine() %>%
glimpse
```
It contains the following columns:
* month <date> `"2017-01-01"`
* station <chr> `"TF1", "France 2", "France Inter", ...`
* prog_type <chr> `"JT", "MAG", "PROG"`
* name <chr> `"Emmanuel Macron", "Marine Le Pen", "François Hollande", ...`
* label <chr> `"Président", "Parti Socialiste", "Ministre", "Les Républicains", ...`
* party <chr> `"Exécutif" , "Ps", "LR", ...`
* time <dbl>
Speaking times are measured in minutes. For instance, in September 2017, Emanuel Macron spoke 8.4 minutes on TF1.
`prog_type` refers to different types of TV/Radio shows:
* `JT`: newscast
* `MAG`: political shows
* `PROG`: non-political shows
### Electoral campaigns
During electoral campaigns - presidential, legislative and local - , the CSA publishes airtime of campaigning candidates [data](https://www.csa.fr/Proteger/Garantie-des-droits-et-libertes/Proteger-le-pluralisme-politique/Pendant-une-election) *every two weeks*.
For each candidate, three different measures are computed:
* `time_candidat`: speaking time of the candidate themselves
* `time_support`: speaking time of personalities supporting the candidate
* `time_mention`: speaking time of journalists mentioning the candidate
This dataset can be accessed using `read_csa_election("pres_2022")`.
Following elections are available:
* Presidential elections 2022: `read_csa_election("pres_2022")`
* Presidential elections 2017: `read_csa_election("pres_2017")`
```{r}
read_csa_election("pres_2022") %>%
dplyr::glimpse()
```
### Updating data
Data will be updated as the CSA publishes new routine and campaign data.
To update the data local version, use `update_csatimer()`
```{r}
# Updating data
update_csatimer()
```
## Example {.tabset}
Here are some graphic examples using `csatimer::read_csa_routine()`
### Example 1
```{r}
read_csa_routine() %>%
group_by(month) %>%
summarise(n_hours = sum(time, na.rm = T)/60) %>%
ggplot(aes(x = month, n_hours)) +
geom_line() +
theme_minimal() +
labs(x = "", y = "Monthly number of hours of political attention", title = "How much do politicians speak in the media?")
```
### Example 2
```{r}
read_csa_routine() %>%
add_station_dummies %>%
mutate(private = ifelse(is_private, "Private", "Public")) %>%
group_by(private, station, month) %>%
summarise(n_hours = sum(time, na.rm = T)/60) %>%
ungroup %>%
mutate(station = fct_reorder(station, n_hours)) %>%
ggplot(aes(x = station, n_hours, fill = private)) +
geom_boxplot(outlier.alpha = 0) +
coord_flip() +
labs(x = "Media outlet", y = "\nMonthly number of hours of political attention", fill = "") +
theme_minimal()
```
### Example 3
```{r}
read_csa_routine() %>%
group_by(party, name) %>%
summarise(n_hours = sum(time, na.rm = T)/60) %>%
ungroup %>%
slice_max(n_hours, n = 20) %>%
mutate(name = fct_reorder(name, n_hours)) %>%
ggplot(aes(x = name, y = n_hours, fill = party)) +
geom_col() +
coord_flip() +
theme_minimal() +
labs(x = "Politicians", y = "Total Number of hours")
```
### Example 4
```{r, fig.height = 5, fig.width = 8}
read_csa_routine() %>%
filter(month > lubridate::dmy("07-01-2021")) %>%
filter(station %in% c("TF1", "France 2", "France 3", "C8")) %>%
group_by(station, party, name) %>%
summarise(n_hours = sum(time, na.rm = T)/60) %>%
ungroup %>%
group_by(station) %>%
slice_max(n_hours, n = 20) %>%
ungroup %>%
mutate(name = fct_reorder(name, n_hours)) %>%
ggplot(aes(x = name, y = n_hours, fill = party)) +
geom_col() +
coord_flip() +
theme_minimal() +
facet_wrap(~station, scales = "free") +
labs(x = "Politicians", y = "Total Number of hours") +
ggtitle("Which politicians obtained the highest attention on four channel since July 2022?")
```