Skip to content

Instantly share code, notes, and snippets.

@charliejhadley
Created January 29, 2019 20:04
Show Gist options
  • Save charliejhadley/f4c85adf23cfb363bc3aab0783fba853 to your computer and use it in GitHub Desktop.
Save charliejhadley/f4c85adf23cfb363bc3aab0783fba853 to your computer and use it in GitHub Desktop.
New follower follow network

BristolR Talk

This script generates a follower follow network from your most recent followers.

I ran this script during my BristolR talk, I've hard coded the followers I got during the talk

## Hard coded ids of new followers during talk
new_followers <- tibble(
  user_id = c(16307367,1571967648,9864992,1409778128, 579777616,29462710,3900399077,45871230,76908793))
library("rtweet")
library("tidyverse")
library("visNetwork")
cnn_fds <- get_followers("martinjhnhadley")
## lookup data on those accounts
cnn_fds_data <- lookup_users(cnn_fds$user_id)
# new_followers <- cnn_fds_data %>%
# select(user_id) %>%
# slice(1:9)
## Hard coded ids of new followers during talk
new_followers <- tibble(
user_id = c(16307367,1571967648,9864992,1409778128, 579777616,29462710,3900399077,45871230,76908793))
get_tweeter_ids <- function(user_id){
followers_data <- get_followers(user_id)
followers_data$user_id %>%
lookup_users() %>%
select(user_id) %>%
.[[1]]
}
follower_network <- new_followers %>%
mutate(following = map(user_id, function(x)get_tweeter_ids(x)))
edges <- follower_network %>%
unnest()
colnames(edges) <- c("from", "to")
unique_ids <- unique(c(edges$from, edges$to))
nodes <- lookup_users(unique_ids)
nodes <- nodes %>%
mutate(id = user_id,
label = screen_name) %>%
select(id, everything()) %>%
mutate(color = if_else(user_id %in% new_followers,
"red",
"#97C2FC"))
visNetwork(nodes, edges) %>%
visIgraphLayout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment