officer-package 是否接受 ggsurvplot-object?
Does officer-package accept ggsurvplot-object?
我正在尝试使用 officer-package 将 ggsurvplot-object 导出到 powerpoint,但没有成功。我能够找到很多关于如何为此使用现在已经过时的 ReporterS-package 的说明,并提到了 officer 也应该工作。文档中似乎没有提到这一点。那么这应该有效吗?是否可以使用这些工具将矢量化生存图转换为 pptx 幻灯片?
totsur <- ggsurvplot(yhd1,
data = sappivertailu,
combine=TRUE,
xlab = "Time, months",
ylab="Survival",
title="Overall survival",
lwd=2,
palette="jco",
xscale = "d_m",
xlim = c(0,730.5),
break.x.by = 91.3,
risk.table = TRUE,
pval = TRUE,
fontsize = 3)
totsur
my_vec_graph <- dml(code = totsur)
doc <- read_pptx()
doc <- add_slide(doc, layout = "Overall survival", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize() )
print(doc, target = "Sappitutkimus/Charts/survi1.pptx")
更改dml(ggobj = totsur)
都不起作用。我做错了什么?
编辑:感谢下面的所有评论!和另一个更新。数据没有任何问题。经过一些调试,我的原始数据产生了预期的结果。
还有一个问题。软件包似乎无法在同一张幻灯片中添加风险 table 和生存曲线。是的,您可以通过在单独的幻灯片上制作两个单独的图来传递它,但我认为这不是一个好习惯。
如果我没有完全弄错的话,officer 和 ReporteRs 有一些共同的代码,并且那里也存在这个问题。 https://github.com/kassambara/survminer/issues/314
有人知道解决这个问题的方法吗?这是我目前正在使用的更紧凑的块。否则这很好用。
yhd1 <- survfit(Surv(sappivertailu$Survi, sappivertailu$Kuolema) ~ Arm, data=koe)
totsur <-
ggsurvplot(yhd1,
combine = TRUE,
data = sappivertailu,
# risk.table = TRUE,
pval = TRUE,
fontsize = 3
)
totsur
my_vec_graph <- rvg::dml(ggobj = last_plot())
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize() )
print(doc, target = "Sappitutkimus/Charts/survi1.pptx")
编辑 n:o 2:以及有关所需结果的提示。
当然可以导出 ggsurvplot
s。通过 officer
到 pptx。您的代码有两个问题。首先你必须使用 rvg::dml(ggobj = ...)
。其次设置 layout = "Overall survival"
。但是 officer
附带的默认 pptx 中没有具有此名称的布局,即您只能使用 pptx 模板中存在的布局。解决这两个问题并使用 ggsurvplot
:
文档中的基本示例
require("survival")
#> Loading required package: survival
library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
library(officer)
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# Basic survival curves
ggsurvplot(fit, data = lung)
my_vec_graph <- rvg::dml(ggobj = last_plot())
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize() )
print(doc, target = "survi2.pptx")
EDIT 如果你想在同一张幻灯片上有多个内容,你可以将布局更改为 Two Content
并使用 ph_location_left/right
:
doc <- read_pptx()
doc <- add_slide(doc, layout = "Two Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_left() )
doc <- ph_with(doc, my_vec_graph, location = ph_location_right() )
print(doc, target = "survi2.pptx")
令我惊讶的是,如果您将求生图嵌入到 print()
语句中,则可以在 dml()
中使用 code =
参数。请务必包含 newpage = FALSE
:
require("survival")
# Loading required package: survival
library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
library(officer)
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# Basic survival curves
p = ggsurvplot(fit, data = lung, risk.table = TRUE)
my_vec_graph <- rvg::dml(code = print(p, newpage = FALSE))
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize() )
print(doc, target = "survi2.pptx")
我正在尝试使用 officer-package 将 ggsurvplot-object 导出到 powerpoint,但没有成功。我能够找到很多关于如何为此使用现在已经过时的 ReporterS-package 的说明,并提到了 officer 也应该工作。文档中似乎没有提到这一点。那么这应该有效吗?是否可以使用这些工具将矢量化生存图转换为 pptx 幻灯片?
totsur <- ggsurvplot(yhd1,
data = sappivertailu,
combine=TRUE,
xlab = "Time, months",
ylab="Survival",
title="Overall survival",
lwd=2,
palette="jco",
xscale = "d_m",
xlim = c(0,730.5),
break.x.by = 91.3,
risk.table = TRUE,
pval = TRUE,
fontsize = 3)
totsur
my_vec_graph <- dml(code = totsur)
doc <- read_pptx()
doc <- add_slide(doc, layout = "Overall survival", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize() )
print(doc, target = "Sappitutkimus/Charts/survi1.pptx")
更改dml(ggobj = totsur)
都不起作用。我做错了什么?
编辑:感谢下面的所有评论!和另一个更新。数据没有任何问题。经过一些调试,我的原始数据产生了预期的结果。
还有一个问题。软件包似乎无法在同一张幻灯片中添加风险 table 和生存曲线。是的,您可以通过在单独的幻灯片上制作两个单独的图来传递它,但我认为这不是一个好习惯。
如果我没有完全弄错的话,officer 和 ReporteRs 有一些共同的代码,并且那里也存在这个问题。 https://github.com/kassambara/survminer/issues/314
有人知道解决这个问题的方法吗?这是我目前正在使用的更紧凑的块。否则这很好用。
yhd1 <- survfit(Surv(sappivertailu$Survi, sappivertailu$Kuolema) ~ Arm, data=koe)
totsur <-
ggsurvplot(yhd1,
combine = TRUE,
data = sappivertailu,
# risk.table = TRUE,
pval = TRUE,
fontsize = 3
)
totsur
my_vec_graph <- rvg::dml(ggobj = last_plot())
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize() )
print(doc, target = "Sappitutkimus/Charts/survi1.pptx")
编辑 n:o 2:以及有关所需结果的提示。
当然可以导出 ggsurvplot
s。通过 officer
到 pptx。您的代码有两个问题。首先你必须使用 rvg::dml(ggobj = ...)
。其次设置 layout = "Overall survival"
。但是 officer
附带的默认 pptx 中没有具有此名称的布局,即您只能使用 pptx 模板中存在的布局。解决这两个问题并使用 ggsurvplot
:
require("survival")
#> Loading required package: survival
library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
library(officer)
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# Basic survival curves
ggsurvplot(fit, data = lung)
my_vec_graph <- rvg::dml(ggobj = last_plot())
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize() )
print(doc, target = "survi2.pptx")
EDIT 如果你想在同一张幻灯片上有多个内容,你可以将布局更改为 Two Content
并使用 ph_location_left/right
:
doc <- read_pptx()
doc <- add_slide(doc, layout = "Two Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_left() )
doc <- ph_with(doc, my_vec_graph, location = ph_location_right() )
print(doc, target = "survi2.pptx")
令我惊讶的是,如果您将求生图嵌入到 print()
语句中,则可以在 dml()
中使用 code =
参数。请务必包含 newpage = FALSE
:
require("survival")
# Loading required package: survival
library(survminer)
#> Loading required package: ggplot2
#> Loading required package: ggpubr
library(officer)
fit<- survfit(Surv(time, status) ~ sex, data = lung)
# Basic survival curves
p = ggsurvplot(fit, data = lung, risk.table = TRUE)
my_vec_graph <- rvg::dml(code = print(p, newpage = FALSE))
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(doc, my_vec_graph, location = ph_location_fullsize() )
print(doc, target = "survi2.pptx")