首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果您使用的是forestplot R包,如何添加脚注?

如果您使用的是forestplot R包,如何添加脚注?
EN

Stack Overflow用户
提问于 2016-10-01 09:00:43
回答 1查看 1.3K关注 0票数 3

请原谅这个天真的问题,因为我是R的新手。我已经使用我在R博客上看到并改编的代码生成了一个森林情节。我想加一个脚注,但我不知道该怎么做。我看过不同的代码,但我不知道哪一个是合适的。任何建议都是非常感谢的!谢谢!

森林地块代码如下:

代码语言:javascript
复制
library(ggplot2)
library(grid)  
library(gridExtra)   
library(xtable)
library(plyr)        
library(MASS)     
library(reshape2)

d1 <- read.csv("/view/name_view/vob/folder/subfolder/forestTAF.csv", stringsAsFactors=FALSE)

#Format data so column labels and columns match required graphical output
subgps <- c(4,5,8,9,12,13,16,17,20,21,24,25,28,29)

#Combine the rest of the columns in the table
tabletext <- cbind(c("Change due to", d1$Variable), 
                c("PK Measures", d1$PK.Measures), 
                c("Recommendation", d1$Recommendation))

#Load forestplot package
library(forestplot)

#Create forest plot
png(filename="forestTAF.png",width=1600, height=640)
forestplot(labeltext=tabletext, graph.pos=3, align=c("l", "c", "l"), 
       mean=c(NA,d1$Point.Estimate), 
       lower=c(NA,d1$Low), upper=c(NA,d1$High),
       title="Drugname \nFold Change and 90% CI",
       xlab="Change Relative to Reference (i.e., without interaction)",
            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=1, cex=0.9, lineheight = "auto", boxsize=0.5, colgap=unit(6,"mm"),
       lwd.ci=2, ci.vertices=TRUE, ci.vertices.height = 0.4)
EN

回答 1

Stack Overflow用户

发布于 2016-10-01 09:26:13

grid::gridtext是一种选择

代码语言:javascript
复制
library('forestplot')

## ?forestplot

row_names <- list(list("test = 1", expression(test >= 2)))
test_data <- data.frame(coef=c(1.59, 1.24),
                        low=c(1.4, 0.78),
                        high=c(1.8, 1.55))
forestplot(row_names, test_data$coef, test_data$low, test_data$high,
           zero = 1, cex  = 2, lineheight = "auto", xlab = "Lab axis txt")

grid::grid.text,其中grid::unit中的"npc"是归一化的0,1坐标,因此图像中的.05将为5%

代码语言:javascript
复制
x <- unit(.05, 'npc')
y <- unit(.05, 'npc')
grid.text('A footnote', x, y, gp = gpar(fontsize=10, font = 3))

或者,您可以使用grid::grid.locator,它允许您指向并单击您想要的位置。

代码语言:javascript
复制
g <- grid.locator('npc')
grid.text('A footnote', g$x, g$y, gp = gpar(fontsize=10, font = 3))

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39801985

复制
相关文章

相似问题

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