Recently Edwin Chen posted a great map of the regional usage of soda vs pop vs coke created from geocoded tweets inolving those words in the context of drinking. http://blog.echen.me/2012/07/06/soda-vs-pop-with-twitter/
He mentions that he used the twitteR package created by Jeff Gentry in R. Sure enough, it is easy to gather tweets that use a given word and put them in a dataframe:
require(twitteR)
require(plyr)
cat.tweets<-searchTwitter("cats",n=1000)
tweets.df = ldply(cat.tweets, function(t) t$toDataFrame() )
the dataframe (tweets.df) will contain the user id, tweet text, etc. for each tweet, but does not appear to contain the geocode. Any idea on how to get it in R?
To do a geographic search, Twitter offers two options: using the near: and within: prefixes or using the geocode: prefix. For the former, to find tweets from the Philadelphia area that mention the word “museum,” you can search for museum near:Philadelphia within:5mi .
To sign up for geolocation on your Twitter account, click your username in the top right-hand corner of the page and select “Settings” from the drop-down menu. Click the check box beside “Add a Location to Your Tweets” to select and enable the feature.
The has:geo operator matches for the presence of either Point or Place geo information within the Twitter payload. Note that this does not allow you to specify specific locations or types of geo data, it simply requires that results have Tweet-specific location information of some kind.
Does geocode mean longitude and latitude coordinate? If yes, following commands works for me.
cat.tweets = searchTwitter("cats",n=1000)
tweets.df = do.call("rbind",lapply(cat.tweets,as.data.frame))
Source : LINK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With