【问题标题】:show x and y co-ordinates on line plot在折线图上显示 x 和 y 坐标
【发布时间】:2019-05-17 09:23:15
【问题描述】:

我是 R 脚本和编码的新手,只是继承了一些 R 代码,我可以完美地绘制并给出正确的结果。当用户将鼠标光标悬停在线时,我希望能够显示 x 和 y 值。

我找到了一篇文章的链接,该链接描述了如何执行必要的步骤,但完全没有运气......

[url="https://www.r-graph-gallery.com/124-change-hover-text-in-plotly/"]

library(dplyr)
library(ggplot2)
library(survival)
library(survminer)
library(grid)
library(gridExtra)
library(plotly)
pc <- dataset
fstat <- pc %>% mutate(fstatus = case_when(OUTCOMETYPE=="Revised" ~ 1,TRUE ~ 0))
pmpa <- fstat %>% select(PRIMARYPROCEDUREID,PRIMARYTOOUTCOMEYEARS,fstatus,OUTCOMETYPE)
if(nrow(pmpa) < 4){
d <- pmpa %>% select(PRIMARYPROCEDUREID,PRIMARYTOOUTCOMEYEARS,OUTCOMETYPE) %>% mutate(INSUFFICIENTDATA = "Summary Results")
h = head(d[,2:4])
grid.table(h)
}else{
fit <- survfit(Surv(PRIMARYTOOUTCOMEYEARS,fstatus)~1,data = pmpa) 
ggsurv <- ggsurvplot(fit,
           ylab="Patient Analysis",
           xlab="Time (Years)",
           break.time.by = 1,
           xlim = c(0,max(fit$time)),
           surv.scale = "percent",
           legend.title = "Kaplan-Meier",
           legend.labs = "",
           risk.table = TRUE,
           fontsize = 3,
           font.tickslab = c(10, "plain"),
           risk.table.y.text = FALSE,
           fun = "event"
           )
ggsurv$plot <- ggsurv$plot + theme(plot.title = element_text(hjust = 0.5, size=18), panel.grid.major = element_line(colour ="grey90"))
ggsurv$table <- ggsurv$table + theme(plot.title = element_text(hjust = 0.5, size = 10))

ggsurv

在折线图上只能看到 x 和 y 坐标的能力。

【问题讨论】:

  • 各位专家。这可以在 R 中做到吗?阅读 plotly 论坛,它看起来很简单,但事实证明很棘手。

标签: r plot coordinates plotly


【解决方案1】:

您可以仅在 ggsurv(它是一个 ggplot 对象)的生存“情节”上调用 ggplotly:

ggplotly(ggsurv$plot)

另请注意,您会收到警告:

geom_GeomConfint() 尚未在 plotly 中实现。

有关缺少置信区间的更多详细信息,请参阅 github 问题:https://github.com/ropensci/plotly/issues/1404

另外 - 要同时显示绘图和表格(KM 曲线位于表格顶部),您可以将“子图”与 plotly 一起使用。如果这有帮助,请告诉我。

【讨论】:

  • 非常感谢 Ben,让我试试这个。非常感谢您的反馈。
猜你喜欢
  • 1970-01-01
  • 2019-11-06
  • 1970-01-01
  • 2018-08-20
  • 1970-01-01
  • 1970-01-01
  • 2021-10-05
  • 2011-02-24
  • 1970-01-01
相关资源
最近更新 更多