-1

the error is shown above. I am trying to plot a graph that show the amount of tweet within each month of 2016. My question is how can I am able to found out the amount of tweet for each month in order for me to plot a graph to see which month tweeted the most.

enter image description here

library(ggplot2)  
library(RColorBrewer)  
library(rstudioapi)

current_path = rstudioapi::getActiveDocumentContext()$path 
setwd(dirname(current_path ))
print( getwd() )

donaldtrump <- read.csv("random_poll_tweets.csv", stringsAsFactors = FALSE)

print(str(donaldtrump))

time8_ts <- ts(random$time8, start = c(2016,8), frequency = 12)
time7_ts <- ts(random$time7, start = c(2016,7), frequency = 12)
time6_ts <- ts(random$time6, start = c(2016,6), frequency = 12)
time5_ts <- ts(random$time5, start = c(2016,5), frequency = 12)
time4_ts <- ts(random$time4, start = c(2016,4), frequency = 12)
time3_ts <- ts(random$time3, start = c(2016,3), frequency = 12)
time2_ts <- ts(random$time2, start = c(2016,2), frequency = 12)
time1_ts <- ts(random$time1, start = c(2016,1), frequency = 12)

browser_mts <- cbind(time8_ts, time7_ts,time6_ts,time5_ts,time4_ts,time3_ts,time2_ts,time1_ts)
dimnames(browser_mts)[[2]] <- c("8","7","6","5","4","3","2","1")

pdf(file="fig_browser_tweet_R.pdf",width = 11,height = 8.5)  
ts.plot(browser_mts, ylab = "Amount of Tweet", xlab = "Month",
        plot.type = "single", col = 1:5)
legend("topright", colnames(browser_mts), col = 1:5, lty = 1, cex=1.75)
Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0
library(lubridate)
library(dplyr)
donaldtrump$created_at <- donaldtrump$created_at |>
  mdy_hm() |>
  floor_date(unit = "month")
donaldtrump |> count(created_at)

Just because you are looking at a time series doesn't mean that you must use a time series object.

If you want a plot:

library(ggplot2)
donaldtrump |>
  count(created_at) |>
  ggplot(aes(created_at, n)) + geom_col() +
  labs(x = "Amount of Tweet", y = "Month")
Isaiah
  • 2,091
  • 3
  • 19
  • 28