【问题标题】:creating an incidence plot with specific data format创建具有特定数据格式的关联图
【发布时间】:2020-12-12 21:32:15
【问题描述】:

我正在尝试使用发病率()命令创建发病率图和流行曲线。我有以下数据where I should be using data_use (class = Date) and new_case (class = int) for the plot。我正在使用以下代码:

library(incidence)

i <- incidence(outbreak, interval = 1)

plot(i, border = "white")

但是,我收到一个错误:is.finite(x) 中的错误:当我运行第二行时,没有为类型“列表”实现默认方法。有没有办法使用这种数据格式和命令创建关联图?感谢您的帮助!

附: Here is an example of the plot I am trying to generate

【问题讨论】:

    标签: r plot


    【解决方案1】:

    我相信这与 incidence 函数期望的参数有关。根据帮助?incidence第一个参数dates是:

    日期向量,可以作为类的对象提供: 整数、数字、日期、POSIXct、POSIXlt 和字符。 (见说明 关于数字和字符格式)

    不完全清楚outbreak 是否是,但大概是包含图像中数据的数据框(列列表)?错误消息可能来自提供数据框而不是日期向量。

    如果您确实有一个数据框,例如示例:

         date_use total_cases new_case
    1  2020-03-01         168       25
    2  2020-03-02         187       19
    3  2020-03-03         200       13
    4  2020-03-04         219       19
    5  2020-03-05         252       33
    6  2020-03-06         295       43
    7  2020-03-07         336       41
    8  2020-03-08         383       47
    9  2020-03-09         470       87
    10 2020-03-10         566       96
    11 2020-03-11         698      132
    

    您可以根据date_usenew_case 创建日期向量:

    my_dates <- rep(df$date_use, df$new_case)
    
    table(my_dates)
    my_dates
    2020-03-01 2020-03-02 2020-03-03 2020-03-04 2020-03-05 2020-03-06 2020-03-07 2020-03-08 2020-03-09 
            25         19         13         19         33         43         41         47         87 
    2020-03-10 2020-03-11 
            96        132
    

    那么你可以使用incidence如下创建关联对象:

    i <- incidence(my_dates, interval = 1)
    
    i
    <incidence object>
    [555 cases from days 2020-03-01 to 2020-03-11]
    
    $counts: matrix with 11 rows and 1 columns
    $n: 555 cases in total
    $dates: 11 dates marking the left-side of bins
    $interval: 1 day
    $timespan: 11 days
    $cumulative: FALSE
    

    然后绘制:

    plot(i, border = "white")
    

    【讨论】:

      猜你喜欢
      • 2015-09-14
      • 1970-01-01
      • 2014-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 2014-10-17
      相关资源
      最近更新 更多