パッケージを使用してマイニングされた Twitter データにテキストを送信しましたrtweet
が、データ フレームに保存した後、パッケージをggplot2
最大限に活用することができません。私は何を間違っていますか?
ライブラリを使用していくつかの Twitter データをテキスト マイニングしrtweet
ましたが、部分的に行ったので、API の制限を超えないようにしました。必要なすべてのデータを収集した後、すべてを 1 つのデータ フレームに結合しました。dplyr
およびパッケージをダウンロードし、ggplot2
時間の経過に伴うツイートを視覚化したかったのですが、データ フレームからの時間変数は認識されません。しかし、マイニングされたデータのバッチの 1 つを元の名前で使用すると、それは時間変数として認識され、適切にプロットされます。これは、データをマイニングし、データ フレームに保存し、それらすべてを 1 つのデータ フレームに結合するために使用したコードです。
##data splits used for mining - 7/8 companies at a time
#1st batch
food_comp1 <- get_timelines(c("accentcatering","angussoftfruits","wmbarrowcliffes","brewdog","brewhouse","capestonefarm","stpierregroupe"), n=3200)
#2nd batch
food_comp2 <- get_timelines(c("cavedirect","brockmoor","cherryfieldltd","fazendagroup","ddcfoods","dairypartners","drakeandmorgan"), n=3200)
#3rd batch
food_comp3 <- get_timelines(c("drinkwarehouse","etsteas","fentimansltd"), n=3200)
#4th batch
food_comp4 <- get_timelines(c("goustocooking","edinburgh_gin","innisandgunn","grapetreefoods","kkfinefoods","finnebrogue","thewhiskyshop"), n=3200)
#5th batch
food_comp5 <- get_timelines(c("onarollsandwich","potsandco","primacheese","purecircle","silburyoils","thealchemistuk"), n=3200)
#6th batch
food_comp6 <- get_timelines(c("artisan_glasgow","thebigprawnco","foodfellas","freshfoodco","wagyurestaurant","charlesfaram","wenzelsthebaker","westerrosssalmo"), n=3200)
#7th batch
food_comp7 <- get_timelines(c("elitefoods_","fevertreemixers","gordon_macphail","gosh_freefrom","specialitydrink"), n=3200)
#merging the datasets into 1
comp <- rbind(food_comp1,food_comp2,food_comp3,food_comp4,food_comp5,food_comp6,food_comp7)
write_as_csv(comp, file_name = "comp", prepend_ids = TRUE, na="", fileEncoding = "UTF-8")
comp <- read.csv("comp.csv", header = TRUE)
View(comp)
#creating a subset with the variables I need
compsubset <- subset(comp, select=c("created_at","screen_name","text","display_text_width","favorite_count","retweet_count","hashtags","media_type","lang"))
write_as_csv(compsubset, file_name = "compsubset", prepend_ids = TRUE, na="", fileEncoding = "UTF-8")
##final dataset with 9 variables
compsubset <- read.csv("compsubset.csv", header=TRUE)
#attemting to create a ggplot with created_at as the time variable (displays year-date-time)
ggplot(data = compsubset, aes(x = created_at)) +
geom_histogram(aes(fill = ..count..)) +
theme(legend.position = "none") +
xlab("Time") + ylab("Number of tweets") +
scale_fill_gradient(low = "midnightblue", high = "aquamarine4")
エラー: StatBin には連続 x 変数が必要です: x 変数は離散的です。おそらく、stat="count" が必要ですか?
データ フレームに変換される前にマイニングされたバッチの 1 つと同じコード
ggplot(data = food_comp1, aes(x = created_at)) +
geom_histogram(aes(fill = ..count..)) +
theme(legend.position = "none") +
xlab("Time") + ylab("Number of tweets") +
scale_fill_gradient(low = "midnightblue", high = "aquamarine4")
この最後の ggplot の後、時間の経過に伴うツイートを含む素敵な棒グラフを取得しました
ツイートを時間でフィルタリングしようとすると同様のことが起こりますdplyr
が、データフレームに入れる前にマイニングされたデータでうまく機能します
comptrial %>%
dplyr::filter(created_at >= "2018-01-01") %>%
dplyr::filter(created_at < "2019-01-01") %>%
dplyr::group_by(screen_name) %>%
ts_plot("days", trim = 1L) +
ggplot2::geom_point() +
ggplot2::theme_minimal() +
ggplot2::theme(
legend.title = ggplot2::element_blank(),
legend.position = "bottom",
plot.title = ggplot2::element_text(face = "bold")) +
ggplot2::labs(
x = NULL, y = NULL,
title = "Frequency of Twitter statuses posted by SMEs",
subtitle = "Twitter status (tweet) counts
caption = "\nSource: Data collected from SME's REST API via rtweet"
)
seq.POSIXt(data[[dtvar]][1], data[[dtvar]][length(data[[dtvar]])] のエラー: 'to' の長さは 1 でなければなりません さらに: 警告メッセージ: 1 : Ops.factor(created_at, "2018-01-01") : '>=' は因子には意味がありません 2: 因子
screen_name
には暗黙の NA が含まれています。使用を検討してforcats::fct_explicit_na
ください 3: 因子screen_name
に暗黙の NA が含まれています。使用を検討してforcats::fct_explicit_na
ください 4: 因子screen_name
に暗黙の NA が含まれています。使用を検討するforcats::fct_explicit_na