首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Forestplot.default中的错误:在平均值参数中提供了2行,而标签有34行

Forestplot.default中的错误:在平均值参数中提供了2行,而标签有34行
EN

Stack Overflow用户
提问于 2018-03-19 23:23:04
回答 1查看 1.6K关注 0票数 0

我正试图在R.

本网站提供的示例:https://designdatadecisions.wordpress.com/2016/07/02/forest-plot-with-horizontal-bands/

首先读取R中的数据。

格式,使列标签和列与匹配

代码语言:javascript
复制
subgps <- c(4,5,8,9,12,13,16,17,20,21,24,25,28,29,32,33)
data$Variable[subgps] <- paste("  ",data$Variable[subgps]) 
np <- ifelse(!is.na(data$Count), paste(data$Count," (",data$Percent,")",sep=""), NA)
tabletext <- cbind(c("Subgroup","\n",data$Variable), 
                    c("No. of Patients (%)","\n",np), 
                    c("4-Yr Cum. Event Rate\n PCI","\n",data$PCI.Group), 
                    c("4-Yr Cum. Event Rate\n Medical Therapy","\n",data$Medical.Therapy.Group), 
                    c("P Value","\n",data$P.Value))

到目前为止还没有出错。

在我尝试执行第二步之后,会出现一个错误。第二步如下:

代码语言:javascript
复制
library(forestplot)
png(file.path(workdir,"Figures\\Forestplot.png"),width=960, height=640)
forestplot(labeltext=tabletext, graph.pos=3, 
           mean=c(NA,NA,data$Point.Estimate), 
           lower=c(NA,NA,data$Low), upper=c(NA,NA,data$High),
           title="Hazard Ratio",
           xlab="     <---PCI Better---    ---Medical Therapy Better--->",
           hrzl_lines=list("3" = gpar(lwd=1, col="#99999922"), 
                          "7" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"),
                          "15" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"),
                          "23" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"),
                          "31" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922")),
           txt_gp=fpTxtGp(label=gpar(cex=1.25),
                              ticks=gpar(cex=1.1),
                              xlab=gpar(cex = 1.2),
                              title=gpar(cex = 1.2)),
           col=fpColors(box="black", lines="black", zero = "gray50"),
           zero=1, cex=0.9, lineheight = "auto", boxsize=0.5, colgap=unit(6,"mm"),
           lwd.ci=2, ci.vertices=TRUE, ci.vertices.height = 0.4)
dev.off()

错误:

Forestplot.default中的错误(标签文本= tabletext,graph.pos = 3,Mean= c(NA,:在平均值参数中提供了2行,而标签有34行)

,这到底是什么意思?如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-19 23:44:34

它说的是什么意思。摘自林图的文档:

均值:具有平均值的向量或矩阵。您还可以提供一个2D/3D矩阵,该矩阵将自动转换为较低/更高的参数。

您检查了data以确保导入正确吗?如果您从博客上的链接下载了它,那么它就是一个.xlsx文件。

例如,当您尝试data$Point.Estimate时,您会看到什么?

如果它是NULL (我怀疑它是空的),那么尝试使用openxlsx包下载它:

代码语言:javascript
复制
install.packages("openxlsx")
library(openxlsx)
data <- read.xlsx("ForestPlotData.csv")
# Presuming you downloaded the file correctly from the url, and its
# in your working directory, and titled "ForestPlotData.csv"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49373970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档