簡體   English   中英

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

[英]How do you add a footnote if you are using the forestplot R package?

請原諒這個天真的問題,因為我是R的新手。我使用我在R博主上看到和改編的代碼生成了一個森林情節。 我想添加一個腳注,但我不知道該怎么做。 我見過不同的代碼,但我不知道哪一個是合適的。 任何建議都非常感謝! 謝謝!

森林地塊代碼如下:

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)

grid::gridtext是一個選項

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其中"npc"grid::unit是歸一化的坐標0,1這樣0.05將橫跨圖像5%

x <- unit(.05, 'npc')
y <- unit(.05, 'npc')
grid.text('A footnote', x, y, gp = gpar(fontsize=10, font = 3))

或者,您可以使用grid::grid.locator ,它允許您指向並單擊您想要的位置。

g <- grid.locator('npc')
grid.text('A footnote', g$x, g$y, gp = gpar(fontsize=10, font = 3))

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM