Created
November 22, 2019 04:15
-
-
Save thoughtfulbloke/9a703b7a3f27150c2f0a42ec03c94589 to your computer and use it in GitHub Desktop.
Code for making graph
This file contains hidden or 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
# tweets are assumed to be gathered for this | |
library(stringr) | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
library(ggthemes) | |
library(ggrepel) | |
library(Rtsne) | |
disc <- read.csv("discussion.csv", stringsAsFactors = FALSE) | |
who <- disc %>% select(status_id, all) %>% | |
unnest_tokens(word,all, token="tweets") %>% | |
filter(str_detect(word, fixed("@"))) %>% | |
group_by(status_id) %>% | |
mutate(responded = gsub("@","", word), | |
response = lead(responded)) %>% ungroup() %>% | |
filter(!is.na(response), responded != response) %>% | |
count(responded, response) | |
whowide <- who %>% spread(response,n, fill=0) | |
tsne <- Rtsne(whowide[,2:ncol(whowide)], dims = 2, perplexity=33, verbose=FALSE, theta=0.0, max_iter = 500, check_duplicates=FALSE) | |
tsne2D <- as.data.frame(tsne$Y) | |
tsne2D$who = whowide$responded | |
arcs = who %>% left_join(tsne2D %>% rename(resdx =V1, resdy=V2), by=c("responded"="who")) %>% | |
left_join(tsne2D %>% rename(resrx =V1, resry=V2), by=c("response"="who")) | |
ggplot(tsne2D, aes(x=V1,y=V2, label=who)) + | |
theme_void() + | |
ggtitle("2 dimesional (TNSE) #DataCharter discussion map, who was responding to who") + | |
geom_curve(data=arcs, aes(x=resdx,y=resdy, xend=resrx, yend=resry, label=NULL, alpha=n)) + | |
geom_point(size=1.2) + | |
geom_text_repel( size=2.5) | |
write.csv(disc %>% | |
mutate(status_id = as.character(status_id)) %>% | |
select(status_id),"ids.csv", row.names = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment