I recently began using the TwitteR package in R to examine my tweeting patterns. One of my first projects was to identify each of my Twitter followers, where they were located, how many tweets they had, and then plot their location on a map using a bubble which was related to their total number of tweets. Unfortunately, I found that I was unable to plot the data on to a spatial map because I did not have the coordinates for each of my followers. While I wasn’t able to successfully complete my project, I am posting my code for acquiring the data using the TwitteR package.
me <- getUser(“username”)
follow = me$getFollowers()
df <- do.call(“rbind”, lapply(follow, as.data.frame))
user = as.character(df$screenName)
name = as.character(df$name)
location = as.character(df$location)
followers = as.character(df$followersCount)
created = as.character(df$created)
mydf = data.frame(user=c(user), name=c(name), location=c(location),
I also attempted to look at the frequency of how often I favorite a tweet that contains an #rstats hashtag. I was able to identify the tweets with #rstats, when they were created, and whether I had marked that tweet as a favorite. After going through and marking various #rstats tweets as favorites, I ran the following code. Unfortunately, I found that each R related tweet was being returned as FALSE in regards to whether I had marked as a favorite. In any case, here is my R code for this task.
tweets <- searchTwitter(‘#rstats’, n=300)
df <- do.call(“rbind”, lapply(tweets, as.data.frame))
ndf <- data.frame(text=c(as.character(df$text)), created=c(df$created),
This was my first real attempt at using the TwitteR package, and I hope to dive further into this package over the next couple weeks. I will work on some new projects and will have some code which successfully completes a particular task.