Created
January 9, 2019 01:08
-
-
Save dubsnipe/d753ec206fd78bc716dce1b6745a5090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(googledrive) | |
require(dplyr) | |
require(tibble) | |
require(tidyr) | |
require(stringr) | |
require(ggplot2) | |
require(stopwords) | |
require(tidytext) | |
human <- tbl_df(read.csv("human_2.csv", encoding = "UTF-8", stringsAsFactors = F)) | |
colnames(human) <- c("time",LETTERS[1:6]) | |
human_count <- human %>% count(A) %>% arrange(desc(n)) | |
ggplot(human_count, aes(x = A, y = n, fill = n)) + geom_bar(stat="identity") + theme(axis.text.x = element_text(angle = 90, hjust = 1, )) | |
words_B <- human %>% | |
select(A,B) %>% | |
unnest_tokens(word,B) %>% | |
filter(!word %in% stopwords("english"), str_detect(word, "[a-z]")) | |
words_C <- human %>% | |
select(A,C) %>% | |
unnest_tokens(word,C) %>% | |
filter(!word %in% stopwords("english"), str_detect(word, "[a-z]")) | |
words_D <- human %>% | |
select(A,D) %>% | |
unnest_tokens(word,D) %>% | |
filter(!word %in% stopwords("english"), str_detect(word, "[a-z]")) | |
words_E <- human %>% | |
select(A,E) %>% | |
unnest_tokens(word,E) %>% | |
filter(!word %in% stopwords("english"), str_detect(word, "[a-z]")) | |
words_F <- human %>% | |
select(A,F) %>% | |
unnest_tokens(word,F) %>% | |
filter(!word %in% stopwords("english"), str_detect(word, "[a-z]")) | |
## | |
words_B <- inner_join(words_B %>% mutate(word_conc = paste(A, word)), | |
words_B %>% mutate(word_conc = paste(A, word)) %>% count(word_conc, sort = TRUE) | |
) %>% | |
arrange(desc(n)) %>% | |
select(A, word, n) | |
head_B <- head(words_B, 50) | |
plot_B <- ggplot(head_B, aes(A, word, fill = n)) + | |
geom_tile(show.legend = FALSE, color="white") + | |
geom_text(aes(label = paste0(n, "%")), color = "white") + | |
theme_classic() + | |
theme(axis.text.x = element_text(angle = 90, hjust = 1, )) | |
## | |
words_C <- inner_join(words_C %>% mutate(word_conc = paste(A, word)), | |
words_C %>% mutate(word_conc = paste(A, word)) %>% count(word_conc, sort = TRUE) | |
) %>% | |
arrange(desc(n)) %>% | |
select(A, word, n) | |
head_C <- head(words_C, 50) | |
plot_C <- ggplot(head_C, aes(A, word, fill = n)) + | |
geom_tile(show.legend = FALSE, color="white") + | |
geom_text(aes(label = paste0(n, "%")), color = "white") + | |
theme_classic() + | |
theme(axis.text.x = element_text(angle = 90, hjust = 1, )) | |
## | |
words_D <- inner_join(words_D %>% mutate(word_conc = paste(A, word)), | |
words_D %>% mutate(word_conc = paste(A, word)) %>% count(word_conc, sort = TRUE) | |
) %>% | |
arrange(desc(n)) %>% | |
select(A, word, n) | |
head_D <- head(words_D, 50) | |
plot_D <- ggplot(head_D, aes(A, word, fill = n)) + | |
geom_tile(show.legend = FALSE, color="white") + | |
geom_text(aes(label = paste0(n, "%")), color = "white") + | |
theme_classic() + | |
theme(axis.text.x = element_text(angle = 90, hjust = 1, )) | |
## | |
words_E <- inner_join(words_E %>% mutate(word_conc = paste(A, word)), | |
words_E %>% mutate(word_conc = paste(A, word)) %>% count(word_conc, sort = TRUE) | |
) %>% | |
arrange(desc(n)) %>% | |
select(A, word, n) | |
head_E <- head(words_E, 50) | |
plot_E <- ggplot(head_E, aes(A, word, fill = n)) + | |
geom_tile(show.legend = FALSE, color="white") + | |
geom_text(aes(label = paste0(n, "%")), color = "white") + | |
theme_classic() + | |
theme(axis.text.x = element_text(angle = 90, hjust = 1, )) | |
## | |
words_F <- inner_join(words_F %>% mutate(word_conc = paste(A, word)), | |
words_F %>% mutate(word_conc = paste(A, word)) %>% count(word_conc, sort = TRUE) | |
) %>% | |
arrange(desc(n)) %>% | |
select(A, word, n) | |
head_F <- head(words_F, 50) | |
plot_F <- ggplot(head_F, aes(A, word, fill = n)) + | |
geom_tile(show.legend = FALSE, color="white") + | |
geom_text(aes(label = paste0(n, "%")), color = "white") + | |
theme_classic() + | |
theme(axis.text.x = element_text(angle = 90, hjust = 1, )) | |
## | |
filename = paste0("plot_B_2", ".png") | |
ggsave( | |
filename = filename, | |
plot = plot_B, | |
device = "png", | |
width = 25, | |
height = 25, | |
units = "cm", | |
dpi = 500 | |
) | |
filename = paste0("plot_C_2", ".png") | |
ggsave( | |
filename = filename, | |
plot = plot_C, | |
device = "png", | |
width = 25, | |
height = 25, | |
units = "cm", | |
dpi = 500 | |
) | |
filename = paste0("plot_D_2", ".png") | |
ggsave( | |
filename = filename, | |
plot = plot_D, | |
device = "png", | |
width = 25, | |
height = 25, | |
units = "cm", | |
dpi = 500 | |
) | |
filename = paste0("plot_E_2", ".png") | |
ggsave( | |
filename = filename, | |
plot = plot_E, | |
device = "png", | |
width = 25, | |
height = 25, | |
units = "cm", | |
dpi = 500 | |
) | |
filename <- paste0("plot_F_2", ".png") | |
ggsave( | |
filename = filename, | |
plot = plot_F, | |
device = "png", | |
width = 25, | |
height = 25, | |
units = "cm", | |
dpi = 500 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment