install.packages("rtweet") install.packages("revgeo") install.packages("tm") install.packages("tidytext") install.packages("igraph") install.packages("dplyr") install.packages("ggplot2") install.packages("tidyverse") install.packages("stringr") install.packages("scales") install.packages("furrr") install.packages("wydir") install.packages("ggraph") library(rtweet) library(revgeo) library(tm) library(tidytext) library(igraph) library(dplyr) library(ggplot2) library(tidyverse) library(stringr) library(knitr) library(scales) library(rtweet) twitter_token <- create_token( app = "ConspApp", consumer_key = "3XTcYTCmb5JcRmsvctfBupaBF", consumer_secret = "QRaEJD2Lrb1ymeWtvVctr4XG5FJRjlaAZO3dnH3zB0oDmyKwo9", access_token="800311264824041472-x0RKc6Ep1F7JeEMozKsqP4zj45JG398", access_secret = "hnZTXa2d2jpjPabe1J4xRAnGcJEamRJnf5KzkiuR5S17a") ## search for 18000 tweets using the metoo hashtag rt <- search_tweets( "#MeToo", n = 18000, include_rts = FALSE ) ## search for 250,000 tweets containing the word data rt <- search_tweets( "data", n = 250000, retryonratelimit = TRUE ) ## search for 10,000 tweets sent from the US rt <- search_tweets( "MeToo", geocode = lookup_coords("usa"), n = 1000 ) ## create lat/lng variables using all available tweet and profile geo-location data rt <- lat_lng(rt) ## plot state boundaries par(mar = c(0, 0, 0, 0)) maps::map("state", lwd = .25) ## plot lat and lng points onto state map with(rt, points(lng, lat, pch = 20, cex = .75, col = rgb(0, .3, .7, .75))) ## random sample for 30 seconds (default) rt <- stream_tweets("") ## stream tweets for a week (60 secs x 60 mins * 24 hours * 7 days) Rt<-stream_tweets( "",timeout = 60 * 60 * 24 * 7,) #Get available trends trends <- trends_available() #See all trends of a specific city Milan<-get_trends(718345) ## get user IDs of accounts followed by Matteo Salvini Matteo_friends <- get_friends("@matteosalvinimi") ## lookup data on those accounts Matteo_friends_data <- lookup_users(Matteo_friends$user_id) ## get user IDs of accounts following Matteo Salvini Matteo_followers <- get_followers("@matteosalvinimi", n = 75000) ## lookup data on those accounts Matteo_followers_data <- lookup_users(Matteo_followers$user_id) tmls <- get_timelines(c("@GiorgiaMeloni", "@matteosalvinimi", "@luigidimaio","@nzingaretti","@emmabonino","@lauraboldrini","@matteorenzi"), n = 320) #Frequency by time Data_series<-ts_data(rt, by = "mins", trim = 0L, tz = "UTC") #Plot time series ts_plot(rt,by="mins") ##For writing your data in csv format attach (rt) #OR attach (tmls) tweetsc<-data.frame(user_id,screen_name,created_at,text,favorite_count,retweet_count,lang,location,followers_count,friends_count,lat,lng,name,listed_count,statuses_count) write.csv2(tweetsc,"filename.csv") ############################################################################################# library(RedditExtractoR) #Find subreddits find_subreddits(keywords) ## Look for links containing the word conspiracy links <- find_thread_urls( keywords = "conspiracy", sort_by = "top", subreddit = NA, period = "month" ) #get the content content <- get_thread_content(links) comments<-content$comments threads<-content$threads View(comments) View(threads) #Find users contents get_user_content(users) ## Create a csv dataset write.cvs2(threads,"filename.csv") #======================================================================================= #STM library(stm) library(readxl) processed <- textProcessor(data$text, metadata = data, lowercase = TRUE, #* removestopwords = TRUE, #* removenumbers = TRUE, #* removepunctuation = TRUE, #* stem = TRUE, #* wordLengths = c(3,Inf), #* sparselevel = 1, #* language = "en", #* verbose = TRUE, #* onlycharacter = TRUE, # not def striphtml = FALSE, #* customstopwords = NULL, #* v1 = FALSE) #* out<-prepDocuments(processed$documents, processed$vocab, processed$meta) meta<-out$meta vocab<-out$vocab docs<-out$documents findingk <- searchK(out$documents, out$vocab, K = c(2:30), data = out$meta, verbose=FALSE) First_STM <- stm(documents = out$documents, vocab = out$vocab, K = 10, prevalence =~ 1, max.em.its = 75, data = out$meta, init.type = "Spectral", verbose = TRUE) ### plot(First_STM) topics<-labelTopics(First_STM,n=15) #see the topic predict_topics<-estimateEffect(formula = 1:6 ~ power, stmobj = First_STM, metadata = out$meta, uncertainty = "Global") summary(predict_topics)