-
Notifications
You must be signed in to change notification settings - Fork 145
/
gdpr.Rmd
165 lines (139 loc) · 4.43 KB
/
gdpr.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
---
name: metrics_gdpr_violations
owner: [email protected]
metrics:
nb_violations:
title: Number of GDPR Violations
description: Number of GDPR Violations in this time period.
nb_total_fine:
title: Total Fine (Euros)
description: Total fine across violations in Euros. (TODO)
dimensions:
country:
title: Country
description: France/Germany/etc
article_title:
title: Article
description: GDPR Article
type:
title: Type
description: Type of violation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
library(lubridate)
library(scales)
theme_set(theme_light())
tuesdata <- tidytuesdayR::tt_load('2020-04-21')
gdpr_violations <- readr::read_tsv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-04-21/gdpr_violations.tsv') %>%
mutate(date = na_if(mdy(date), "1970-01-01")) %>%
rename(country = name)
```
```{r}
gdpr_violations %>%
summarize(total = sum(price))
gdpr_violations %>%
count(country = fct_lump(country, 8, w = price),
sort = TRUE, wt = price, name = "total_price") %>%
mutate(country = fct_reorder(country, total_price)) %>%
ggplot(aes(total_price, country)) +
geom_col() +
scale_x_continuous(labels = dollar_format())
```
```{r}
gdpr_violations %>%
count(month = floor_date(date, "month"),
country = fct_lump(country, 6, w = price),
sort = TRUE, wt = price, name = "total_price") %>%
mutate(country = fct_reorder(country, -total_price, sum)) %>%
ggplot(aes(month, total_price, fill = country)) +
geom_col() +
scale_y_continuous(labels = dollar_format()) +
labs(x = "Time",
y = "Total fines",
fill = "Country")
```
```{r}
gdpr_violations %>%
count(source, country, sort = TRUE)
gdpr_violations %>%
select(controller, date, article_violated, type, summary, price) %>%
mutate(summary = str_trunc(summary, 140)) %>%
arrange(desc(price)) %>%
mutate(price = dollar(price)) %>%
head(10)
```
```{r}
gdpr_violations %>%
mutate(type = fct_lump(type, 8, w = price),
type = fct_reorder(type, price),
country = fct_lump(country, 5)) %>%
ggplot(aes(price, type)) +
geom_boxplot() +
geom_jitter(aes(color = country), width = 0, height = .25) +
scale_x_log10(labels = dollar_format())
```
### Which article was violated?
```{r}
article_titles <- gdpr_text %>%
distinct(article, article_title)
separated_articles <- gdpr_violations %>%
separate_rows(article_violated, sep = "\\|") %>%
extract(article_violated, "article", "Art\\. ?(\\d+)", convert = TRUE, remove = FALSE) %>%
left_join(article_titles, by = "article") %>%
mutate(article_title = paste0(article, ". ", str_trunc(article_title, 50)),
article_title = ifelse(is.na(article), "Unknown", article_title)) %>%
add_count(id) %>%
mutate(price_per_article = price / n)
separated_articles %>%
group_by(article = fct_lump(article_title, 8, w = price)) %>%
summarize(total_fine = sum(price_per_article),
violations = n()) %>%
arrange(desc(total_fine)) %>%
mutate(article = fct_reorder(article, total_fine)) %>%
ggplot(aes(total_fine, article)) +
geom_col() +
scale_x_continuous(labels = dollar_format()) +
labs(title = "What articles got the most fines?",
y = "",
x = "Total fine")
```
```{r}
gdpr_text <- tuesdata$gdpr_text
```
```{r}
gdpr_violations %>%
filter(str_detect(controller, "Vodafone")) %>%
group_by(date, country) %>%
summarize(violations = n(),
total_fine = sum(price)) %>%
ggplot(aes(date, total_fine, size = violations, color = country)) +
geom_point() +
scale_y_continuous(labels = dollar_format()) +
scale_size_continuous(guide = FALSE) +
labs(title = "Vodafone's GDPR violations",
color = "",
x = "Time",
y = "Total fine on this day")
```
```{r}
library(tidymetrics)
summarized <- separated_articles %>%
filter(!is.na(date)) %>%
mutate(country = fct_lump(country, 6, w = price_per_article),
article_title = fct_lump(article_title, 6, w = price_per_article),
type = fct_lump(type, 6, w = price_per_article)) %>%
cross_by_dimensions(country, article_title, type) %>%
cross_by_periods(c("month", "quarter")) %>%
summarize(nb_violations = n_distinct(id),
nb_total_fine = sum(price_per_article)) %>%
ungroup()
gdpr_metrics <- create_metrics(summarized)
```
```{r}
library(shinymetrics)
preview_metric(gdpr_metrics$gdpr_violations_nb_violations)
```