我应该如何格式化日期来制作时间序列线图?

问题描述 投票:0回答:1

我有小事发生

   count_ date_              
    <int> <dttm>             
 1     NA 1923-01-01 00:00:00
 2     NA 1923-01-01 00:00:00
 3     NA 1923-01-01 00:00:00
 4     NA 1923-01-01 00:00:00
 5      1 1923-03-23 00:00:00
 6      1 1923-03-23 00:00:00
 7      1 1923-03-23 00:00:00
 8      1 1923-03-23 00:00:00
 9      1 1923-03-26 00:00:00
10      1 1923-03-26 00:00:00

我尝试修复 count_ 中的空值和 date_ 中的格式...

occurrences <- occurrences %>%
  mutate(
    count_ = replace_na(count_, 1),
    date_ = as_date(date_)
  )
head(occurrences)
------------------------------------------------------------------------
   count_ date_     
    <int> <date>    
 1      1 1923-01-01
 2      1 1923-01-01
 3      1 1923-01-01
 4      1 1923-01-01
 5      1 1923-03-23
 6      1 1923-03-23
 7      1 1923-03-23
 8      1 1923-03-23
 9      1 1923-03-26
10      1 1923-03-26

然后我尝试用变异字段制作一个 geom_line 图...

ggplot(occurrencesTibble, mapping = aes(date_, count_)) +
  geom_line()

但是我得到 this,其中有条形而不是线条。

我尝试将字段更改为小数和数字,以便连续绘制它们,但我不断得到错误类型的图表。

r ggplot2 time-series rstudio line-plot
1个回答
0
投票

抱歉无法发表评论,因为我的声誉不够高,但是您尝试过绘制更短的时间吗?它看起来像是一个折线图,但你有一些相当可变的数据,所以跳跃看起来像条形

© www.soinside.com 2019 - 2024. All rights reserved.