Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(twitteR)
- library(tm)
- library(wordcloud)
- library(RColorBrewer)
- api_key <- "c1OvJfvNxzd4H01PzVpGQSQM1"
- api_secret <- "Qxe1JKMJefn22HQnWHTP46LnFx86eyHf9Qc24nOfuimHceQwAW"
- access_token <- "1095432120-csFurAKhaOAVVIwMQFEGPoNoIUwFTcFqaZUHDL2"
- access_token_secret <- "0zeEh45a2l6jiHkJYjbyOURGcodd9pncsgQR3jYT2hsWq"
- setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
- tweets <- searchTwitter("#NASA",lang = "pt", n = 250)
- # Create an empty character vector of the same length as the number of
- # tweets
- l <- length(tweets)
- tweeter <- vector(mode = "character", length = l)
- # Extract the screen names from each tweet status
- for (i in 1:l) tweeter[i] <- tweets[[i]]$getScreenName()
- # Compile the frequencies of each screen name
- tweeter.freq <- table(tweeter)
- # Black backgrounds are 'this year's colour' in terms of dataviz!
- par(bg = "grey")
- # Draw the word cloud
- wordcloud(names(tweeter.freq), tweeter.freq, colors = c("tomato",
- "wheat", "lightblue"), scale = c(6, 0.5), random.color = TRUE, rot.per = 0.5,
- min.freq = 1, font = 2, family = "serif")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement