按日期绘制事件 - seq.int(0, to0 - from, by) 中的错误:'to' 必须是有限数
Plotting occurrences by date - Error in seq.int(0, to0 - from, by) : 'to' must be a finite number
我有一个以这种方式制作的推文数据集:
mydata <- read.csv(header=TRUE, text='"tweet","Topic","created_at"
"text1","topic1","2020-08-13"
"text2","topic2","2020-08-11"
"text3","topic2","2020-08-11"
"text4","topic2","2020-08-10"
"text5","topic1","2020-08-13"
"text6","topic1","2020-08-14"
"text7","topic1","2020-08-15"')
我想每天绘制每个主题随时间推移的发生情况(例如,如果在 2020-08-11 有 5 条推文属于主题 1 和 2 条推文属于主题 2,则值那天的主题 1 将是 5,主题 2 将是 2,依此类推),我正在尝试使用以下代码来完成:
mydata%>%
mutate(created_at = lubridate::ymd_hms(created_at),
date = as.Date(created_at)) %>%
count(date, Topic) %>%
ggplot(aes(date, n, color = Topic)) + geom_line()+
labs(y="n° tweets")
但是我收到这个错误:
Error in seq.int(0, to0 - from, by) : 'to' must be a finite number
我能做什么?
我的目标是这样的结果:
created_at
没有 lubridate::ymd_hms()
的正确格式,这会在您的数据集中创建 NA
值。您可以简单地删除它并使用 as.Date()
并且您的代码会执行您想要的操作:
mydata %>%
mutate(date = as.Date(created_at)) %>%
count(date, Topic) %>%
ggplot(aes(date, n, color = Topic)) + geom_line()+
labs(y="n° tweets")
我有一个以这种方式制作的推文数据集:
mydata <- read.csv(header=TRUE, text='"tweet","Topic","created_at"
"text1","topic1","2020-08-13"
"text2","topic2","2020-08-11"
"text3","topic2","2020-08-11"
"text4","topic2","2020-08-10"
"text5","topic1","2020-08-13"
"text6","topic1","2020-08-14"
"text7","topic1","2020-08-15"')
我想每天绘制每个主题随时间推移的发生情况(例如,如果在 2020-08-11 有 5 条推文属于主题 1 和 2 条推文属于主题 2,则值那天的主题 1 将是 5,主题 2 将是 2,依此类推),我正在尝试使用以下代码来完成:
mydata%>%
mutate(created_at = lubridate::ymd_hms(created_at),
date = as.Date(created_at)) %>%
count(date, Topic) %>%
ggplot(aes(date, n, color = Topic)) + geom_line()+
labs(y="n° tweets")
但是我收到这个错误:
Error in seq.int(0, to0 - from, by) : 'to' must be a finite number
我能做什么?
我的目标是这样的结果:
created_at
没有 lubridate::ymd_hms()
的正确格式,这会在您的数据集中创建 NA
值。您可以简单地删除它并使用 as.Date()
并且您的代码会执行您想要的操作:
mydata %>%
mutate(date = as.Date(created_at)) %>%
count(date, Topic) %>%
ggplot(aes(date, n, color = Topic)) + geom_line()+
labs(y="n° tweets")