R関数を使用していましたが、検索テキスト、検索サイトの数、各サイトの周りの半径を入力しました。たとえばtwitterMap("#rstats",10,"10mi")
のために、ここでのコードです:私はどのように対処するかわからないということに遭遇しましたいくつかの大きな問題がある
twitterMap <- function(searchtext,locations,radius){
require(ggplot2)
require(maps)
require(twitteR)
#radius from randomly chosen location
radius=radius
lat<-runif(n=locations,min=24.446667, max=49.384472)
long<-runif(n=locations,min=-124.733056, max=-66.949778)
#generate data fram with random longitude, latitude and chosen radius
coordinates<-as.data.frame(cbind(lat,long,radius))
coordinates$lat<-lat
coordinates$long<-long
#create a string of the lat, long, and radius for entry into searchTwitter()
for(i in 1:length(coordinates$lat)){
coordinates$search.twitter.entry[i]<-toString(c(coordinates$lat[i],
coordinates$long[i],radius))
}
# take out spaces in the string
coordinates$search.twitter.entry<-gsub(" ","", coordinates$search.twitter.entry ,
fixed=TRUE)
#Search twitter at each location, check how many tweets and put into dataframe
for(i in 1:length(coordinates$lat)){
coordinates$number.of.tweets[i]<-
length(searchTwitter(searchString=searchtext,n=1000,geocode=coordinates$search.twitter.entry[i]))
}
#making the US map
all_states <- map_data("state")
#plot all points on the map
p <- ggplot()
p <- p + geom_polygon(data=all_states, aes(x=long, y=lat, group = group),colour="grey", fill=NA)
p<-p + geom_point(data=coordinates, aes(x=long, y=lat,color=number.of.tweets
)) + scale_size(name="# of tweets")
p
}
# Example
searchTwitter("dolphin",15,"10mi")
。まず、書かれているように、コードはランダムに生成された15の異なる場所を検索します。これらの位置は、米国東西の最大経度から最大西まで、最も遠い北から最南端までの一様分布から生成されます。これには、カナダの森林のミネソタ州の湖の東にある、合衆国以外の場所が含まれます。生成された場所が米国にあるかどうかをランダムにチェックし、そうでない場合は破棄する関数を使用したいと思います。もっと重要なのは、何千もの場所を検索したいのですが、twitterはそれが好きではなく、420 error enhance your calm
です。だから、たぶん数時間ごとに検索し、ゆっくりとデータベースを構築し、重複したつぶやきを削除するのがベストでしょう。最後に、遠隔で人気のあるトピックを選択すると、RはError in function (type, msg, asError = TRUE) : transfer closed with 43756 bytes remaining to read
のようなエラーを返します。私はこの問題を回避する方法について少し謎に包まれています。
あなたは 'searchTwitter'が使用する' geocode'を提供する必要があります。ライブラリのドキュメント '?searchTwitter'を参照してください。 –
私は、あなたが 'searchTwitter'にジオコードと半径を与えることができますが、それは引っ張られたツイートごとにジオコードを生成しないことがわかります。 – iantist
しかし、あなたが提供したジオコードは正しいでしょうか?より小さな半径で、必要なものを与えるかもしれませんか? –