Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dubsnipe
Last active December 11, 2018 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubsnipe/c681db3f764db96962088a38c52689ba to your computer and use it in GitHub Desktop.
Save dubsnipe/c681db3f764db96962088a38c52689ba to your computer and use it in GitHub Desktop.
require(googledrive)
require(dplyr)
require(tibble)
require(tidyr)
require(stringr)
require(ggplot2)
require(stopwords)
human <- tbl_df(read.csv("human.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", ".png")
ggsave(
filename = filename,
plot = plot_B,
device = "png",
width = 25,
height = 25,
units = "cm",
dpi = 500
)
filename = paste0("plot_C", ".png")
ggsave(
filename = filename,
plot = plot_C,
device = "png",
width = 25,
height = 25,
units = "cm",
dpi = 500
)
filename = paste0("plot_D", ".png")
ggsave(
filename = filename,
plot = plot_D,
device = "png",
width = 25,
height = 25,
units = "cm",
dpi = 500
)
filename = paste0("plot_E", ".png")
ggsave(
filename = filename,
plot = plot_E,
device = "png",
width = 25,
height = 25,
units = "cm",
dpi = 500
)
filename <- paste0("plot_F", ".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