我在 R 中生成 kaplan-meier 圖,我想知道是否有辦法使用該plotly包創建互動式 kaplan-meier 圖?理想情況下,我希望能夠使用滑鼠游標跟蹤生存“線”,plotly工具提示框告訴我組、生存率和時間。
這是我想在其中重新創建的生存分析的模擬示例plotly:-
library(survival)
library(ranger)
library(ggplot2)
library(dplyr)
library(ggfortify)
library(plotly)
#------------
data(veteran)
head(veteran)
km_trt_fit <- survfit(Surv(time, status) ~ trt, data=veteran)
#using autoplot to create graph
autoplot(km_trt_fit)

但是當我嘗試使用時plotly,我收到了這個錯誤:-
ggplotly(km_trt_fit)
#Error in UseMethod("ggplotly", p) :
#no applicable method for 'ggplotly' applied to an object of class "survfit"
我需要采取哪些額外步驟才能使km_trt_fit變數適合該ggplotly函式?我能否在工具提示中看到我上面概述的功能?非常感謝 :)
uj5u.com熱心網友回復:
一種選擇是從ggsurvplot物件中提取 ggplot 圖形。
library(survminer)
p <- ggsurvplot(km_trt_fit)
ggplotly(p[[1]])
要獲取不同時間點事件的表格資料,您可以使用p[[3]].
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/432033.html
標籤:r ggplot2 情节地 生存分析 ggplotly
下一篇:iceberg合并小檔案沖突測驗
