英文:
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)
#> 绘制"来自癌症的死亡"结果。
<!-- -->
<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)
#> Loading required package: ggplot2
# install.packages("tidycmprsk")
library(tidycmprsk)
cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %>%
ggcuminc()
#> 绘制"来自癌症的死亡"结果。
<!-- -->
cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %>%
ggcuminc() +
geom_step(aes(x = time, y = estimate),
linewidth = 2,
inherit.aes = FALSE)
#> 绘制"来自癌症的死亡"结果。
<!-- -->
<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)
#> Loading required package: ggplot2
# install.packages("tidycmprsk")
library(tidycmprsk)
cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
ggcuminc(linewidth = 0.5, lty = 2)
#> Plotting outcome "death from cancer".
<!-- -->
<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)
#> Loading required package: ggplot2
# install.packages("tidycmprsk")
library(tidycmprsk)
cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %>%
ggcuminc()
#> Plotting outcome "death from cancer".
<!-- -->
cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %>%
ggcuminc() +
geom_step(aes(x = time, y = estimate),
linewidth = 2,
inherit.aes = FALSE)
#> Plotting outcome "death from cancer".
<!-- -->
<sup>Created on 2023-03-07 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论