Want to find out the favourite topics (as measured by their preferred hashtags) for any Twitter user? It's easy to do, thanks to this R language program by Mark T Patterson. Here are the top 20 results for Barack Obama, based on his most recent 3200 tweets (notice that #immigration has jumped to #2 on the list since Mark ran his analysis yesterday).
If you'd like to do the sama analysis on a different twitter user, you'll need to run the script in R, with the twitteR package installed (use install.packages("twitteR") ). You'll also need to register for a Twitter developer account and register a new Twitter app — it's quick and easy to do, and this page has useful information if you're not sure. I had to modify the first few lines of Mike's script as follows, substituting the consumer key and consumer secret provided by Twitter after registering my app.
cred <- getTwitterOAuth("my_consumer_key","my_consumer_secret") registerTwitterOAuth(cred) tw = userTimeline("BarackObama", n = 3200)
Tip: don't forget to save("cred",file="twitter-cred.Rd") so you can load("~/R/twitter-cred.Rd") for use in a future script that uses twitterR. To run the script for a different user, change "BarackObama" in the third line of the script above to any other vald Twitter username. Here's mine! This version of the script makes the user name a variable and modifies the plot title accordingly.
Decisions and R: Using R to find Obama's most frequent twitter hashtags
Where is the function getTwitterOAuth found?
Posted by: James | November 06, 2013 at 03:34
@James, it's part of the twitteR package. Here's its documentation.
Posted by: David Smith | November 06, 2013 at 12:44