Original: http://tecdat.cn/?p=387

Twitter is a popular social network, and there’s a lot of data waiting to be analyzed. The Twitter R package is a good tool for text mining of Twitter data. This article is about how to use the Twitter R package to get Twitter data, import it into R, and then do some interesting data analysis on it.

The first step is to register your application.

To be able to access Twitter data programming, we need to create an application that interacts with Twitter’s API.

After registering you will receive a key and password:

After obtaining the key and password, we can authorize our application in R to access Twitter on our behalf:

Depending on the search term, we can collect tens of thousands of tweets in a matter of minutes. Here we test the Twitter results of a keyword littleCaesars:

Grab the latest 1000 related tweets

Since the default fetch result is in JSON format, the twlistToDF function is used to convert it into a data box

Then we do some simple text cleanup

From the obtained data, we can see the time, content, latitude and longitude of Twitter posts and other information

After cleaning up the data, we segmented the Twitter content for data visualization

After segmentation, you can get the high frequency words associated with Twitter, and then visualize them

In addition, the time-stamp data and geographical data in the data can also be combined for visual analysis

If you’ve been thinking about applying sentiment analysis to some textual data, you may find that using R is easier than you thought!

\ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =