使用ggsurvfit包中的ggcuminc时出现错误。

huangapple go评论74阅读模式
英文:

Error when using ggcuminc from the package ggsurvfit

问题

我在使用ggsurvfit包的ggcuminc函数绘制累积发病率函数时遇到了一个错误。

这是一个示例:

cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
    ggcuminc(outcome = "death from cancer") +
    geom_step(linewidth = 1)

我收到以下错误消息:

Error in `geom_step()`:
! Problem while setting up geom.
ℹ Error occurred in the 2nd layer.
Caused by error in `compute_geom_1()`:
! `geom_step()` requires the following missing aesthetics: x and y

这个错误是最近两个月内出现的。我无法确定发生了什么。有什么想法吗?

顺便说一下,ggplot2 3.4.0版本中已弃用线条的size美学,而改为使用linewidth

提前感谢。

英文:

I have been getting an error when plotting a cumulative incidence function using ggcuminc from the package ggsurvfit.

Here is an example:

cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
    ggcuminc(outcome = "death from cancer") +
    geom_step(linewidth = 1)

I get the error:

Error in `geom_step()`:
! Problem while setting up geom.
ℹ Error occurred in the 2nd layer.
Caused by error in `compute_geom_1()`:
! `geom_step()` requires the following missing aesthetics: x and y

This error is recent and occurred in the last 2 months. I can't figure out what happened exactly. Any ideas?

btw: The size aesthetic for lines was deprecated in ggplot2 3.4.0, and was replaced with linewidth instead.

Thanks in forward

答案1

得分: 1

以下是翻译好的内容:

Update:

Looking at the source code you can pass linewidth/linetype/etc parameters to ggcuminc() directly via the ellipsis (dot-dot-dot) argument, e.g.

library(ggsurvfit)
#> Loading required package: ggplot2
# install.packages("tidycmprsk")
library(tidycmprsk)

cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
  ggcuminc(linewidth = 0.5, lty = 2)
#> 绘制"来自癌症的死亡"结果。

使用ggsurvfit包中的ggcuminc时出现错误。<!-- -->

<sup>2023-03-07创建,使用reprex v2.0.2</sup>

Hopefully this will work for your use-case, but if not please leave a comment and I'll see what other potential workarounds there might be.


Original answer:

I don't understand what you're trying to do, but if you want to plot geom_step() on top of your ggcuminc() step you can specify your x and y axes and add inherit.aes = FALSE, e.g.

library(ggsurvfit)
#&gt; Loading required package: ggplot2
# install.packages(&quot;tidycmprsk&quot;)
library(tidycmprsk)

cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %&gt;%
  ggcuminc()
#&gt; 绘制"来自癌症的死亡"结果。

使用ggsurvfit包中的ggcuminc时出现错误。<!-- -->


cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %&gt;%
  ggcuminc() +
  geom_step(aes(x = time, y = estimate),
            linewidth = 2,
            inherit.aes = FALSE)
#&gt; 绘制"来自癌症的死亡"结果。

使用ggsurvfit包中的ggcuminc时出现错误。<!-- -->

<sup>2023-03-07创建,使用reprex v2.0.2</sup>

英文:

Update:

Looking at the source code you can pass linewidth/linetype/etc parameters to ggcuminc() directly via the ellipsis (dot-dot-dot) argument, e.g.

library(ggsurvfit)
#&gt; Loading required package: ggplot2
# install.packages(&quot;tidycmprsk&quot;)
library(tidycmprsk)

cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %&gt;%
  ggcuminc(linewidth = 0.5, lty = 2)
#&gt; Plotting outcome &quot;death from cancer&quot;.

使用ggsurvfit包中的ggcuminc时出现错误。<!-- -->

<sup>Created on 2023-03-07 with reprex v2.0.2</sup>

Hopefully this will work for your use-case, but if not please leave a comment and I'll see what other potential workarounds there might be.


Original answer:

I don't understand what you're trying to do, but if you want to plot geom_step() on top of your ggcuminc() step you can specify your x and y axes and add inherit.aes = FALSE, e.g.

library(ggsurvfit)
#&gt; Loading required package: ggplot2
# install.packages(&quot;tidycmprsk&quot;)
library(tidycmprsk)

cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %&gt;%
  ggcuminc()
#&gt; Plotting outcome &quot;death from cancer&quot;.

使用ggsurvfit包中的ggcuminc时出现错误。<!-- -->


cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %&gt;%
  ggcuminc() +
  geom_step(aes(x = time, y = estimate),
            linewidth = 2,
            inherit.aes = FALSE)
#&gt; Plotting outcome &quot;death from cancer&quot;.

使用ggsurvfit包中的ggcuminc时出现错误。<!-- -->

<sup>Created on 2023-03-07 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年3月7日 08:36:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定