-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHillaryClintonEmails.RMD
More file actions
49 lines (41 loc) · 1.36 KB
/
Copy pathHillaryClintonEmails.RMD
File metadata and controls
49 lines (41 loc) · 1.36 KB
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
---
title: "Hillary Clinton Emails"
author: "Vadim Katsemba"
date: "December 21, 2015"
output: pdf_document
---
The Hillary Clinton email controversy is still ongoing, let's investigate some of the emails.
First, we must connect to the database.
```{r}
library(RSQLite)
database <- dbConnect(dbDriver("SQLite"), "database.sqlite")
```
Then we shall look at who the most common senders were.
```{r}
senders <- dbGetQuery(database, "SELECT p.Name, COUNT(p.Name) SentEmails
FROM Emails e
INNER JOIN Persons p ON e.SenderPersonId=p.Id
GROUP BY p.Name
ORDER BY COUNT(p.Name) DESC
LIMIT 5")
```
We shall use a bar graph to represent the number of emails sent for every sender.
```{r}
library(ggplot2)
ggplot(senders, aes(x=reorder(Name, SentEmails), y=SentEmails)) + geom_bar(stat="identity") + labs(x="Sender", y="Emails Sent")
```
We are going to repeat the same process for the e-mail recipients.
```{r}
recipients <- dbGetQuery(database, "SELECT p.Name, COUNT(p.Name) ReceivedEmails
FROM Emails e
INNER JOIN EmailReceivers r ON r.EmailId=e.Id
INNER JOIN Persons p ON r.PersonId=p.Id
GROUP BY p.Name
ORDER BY COUNT(p.Name) DESC
LIMIT 5")
```
And again, a bar graph represents the amount of emails for every recipient.
```{r}
library(ggplot2)
ggplot(recipients, aes(x=reorder(Name, ReceivedEmails), y=ReceivedEmails)) + geom_bar(stat="identity") + labs(x="Recipient", y="Emails Received")
```