【发布时间】:2020-11-27 07:05:06
【问题描述】:
我在这里学习 R 教程https://rviews.rstudio.com/2017/09/25/survival-analysis-with-r/
我用于工作的计算机没有互联网访问权限,也没有 USB 端口 - 它只有 R 和一些预装的库。本教程需要“survival”、“ggplot2”、“ranger”、“dplyr”和“ggfortify”。我用于工作的计算机具有所有这些库,除了 ggfortfiy。显然,ggfortify 库中需要一个名为“autoplot”的函数来制作本教程中的一些绘图。
当我尝试运行教程中的代码时:
#load libraries
library(survival)
library(ranger)
library(ggplot2)
library(dplyr)
#load data
data(veteran)
head(veteran)
# Kaplan Meier Survival Curve
km <- with(veteran, Surv(time, status))
km_fit <- survfit(Surv(time, status) ~ 1, data=veteran)
#plot(km_fit, xlab="Days", main = 'Kaplan Meyer Plot') #base graphics is always ready
#here is where the error is
autoplot(km_fit)
我收到以下错误:Error: Objects of type survfit not supported by autoplot.
有谁知道如何解决这个问题?如果没有 ggfortify 库,是否可以制作类似的图?可以只用ggplot2制作吗?
在我的个人电脑上,一旦我安装了 ggfortify 库,我就可以制作这个绘图了。
(注意:我也没有“survminer”库)
谢谢
【问题讨论】:
标签: r ggplot2 plot graph data-visualization