Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. library(twitteR)
  2. library(tm)
  3. library(wordcloud)
  4. library(RColorBrewer)
  5.  
  6.  
  7. api_key <- "c1OvJfvNxzd4H01PzVpGQSQM1"
  8.  
  9. api_secret <- "Qxe1JKMJefn22HQnWHTP46LnFx86eyHf9Qc24nOfuimHceQwAW"
  10.  
  11. access_token <- "1095432120-csFurAKhaOAVVIwMQFEGPoNoIUwFTcFqaZUHDL2"
  12.  
  13. access_token_secret <- "0zeEh45a2l6jiHkJYjbyOURGcodd9pncsgQR3jYT2hsWq"
  14.  
  15. setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
  16.  
  17.  
  18. tweets <- searchTwitter("#NASA",lang = "pt", n = 250)
  19.  
  20.  
  21. # Create an empty character vector of the same length as the number of
  22. # tweets
  23. l <- length(tweets)
  24. tweeter <- vector(mode = "character", length = l)
  25.  
  26. # Extract the screen names from each tweet status
  27. for (i in 1:l) tweeter[i] <- tweets[[i]]$getScreenName()
  28.  
  29.  
  30. # Compile the frequencies of each screen name
  31. tweeter.freq <- table(tweeter)
  32.  
  33.  
  34. # Black backgrounds are 'this year's colour' in terms of dataviz!
  35. par(bg = "grey")
  36.  
  37. # Draw the word cloud
  38. wordcloud(names(tweeter.freq), tweeter.freq, colors = c("tomato",
  39. "wheat", "lightblue"), scale = c(6, 0.5), random.color = TRUE, rot.per = 0.5,
  40. min.freq = 1, font = 2, family = "serif")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement