-
Notifications
You must be signed in to change notification settings - Fork 2
/
simpsons.Rmd
27 lines (18 loc) · 926 Bytes
/
simpsons.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
---
title: "Simpsons Characters"
output: html_notebook
---
```{r, error=TRUE}
ep_char <- read.csv2("support/simpsons_ep-char.csv", sep = ",")
characters <- read.csv2("support/simpsonsNodes.csv", sep = ",")
chars <- ep_char$character_id
eps <- ep_char$episode_id
char_freq <- as.data.frame(table(chars))
most_freq_chars <- head(char_freq[order(-char_freq$Freq), , drop = FALSE])
most_freq_vals <- head(char_freq[order(-char_freq$Freq), , drop = FALSE]$Freq)
most_freq_ids <- head(char_freq[order(-char_freq$Freq), , drop = FALSE]$chars)
no_eps <- tail(eps, n=1)
perc_freq <- unlist(lapply(most_freq_vals, function (char) return(round(char / no_eps * 100, 1))))
character_names <- unlist(lapply(most_freq_ids, function (index) return(characters$char_name[index])))
barplot(perc_freq, width = 1, xlab="Character Names", ylab="Percentage episodes", ylim=c(0,100), col=rainbow(6), legend=strtrim(character_names, 20))
```