R语言绘图包系列:
- R语言绘图包01--优秀的拼图包patchwork
- R语言绘图包02--热图pheatmap
- R语言绘图包03--火山图EnhancedVolcano
- R语言绘图包04--GOplot:富集分析结果可视化
- R语言绘图包05--韦恩图的绘制:ggvenn和VennDiagram
- R语言绘图包06--基因表达相关性绘图corrplot
- R语言绘图包07--多集合可视化UpSetR
- R语言绘图包08--森林图的绘制:forestplot
- R语言绘图包09--序列分析图的绘制ggseqlogo
- R语言绘图包10--Circos图的绘制:circlize包
- 加载包
install.packages('forestploter')
library(forestploter)
- 准备数据
# Read provided sample example data
dt <- read.csv(system.file("extdata", "example_data.csv", package = "forestploter"))
# Keep needed columns
dt <- dt[,1:6]
# indent the subgroup if there is a number in the placebo column
dt$Subgroup <- ifelse(is.na(dt$Placebo),
dt$Subgroup,
paste0(" ", dt$Subgroup))
# NA to blank or NA will be transformed to carachter.
dt$Treatment <- ifelse(is.na(dt$Treatment), "", dt$Treatment)
dt$Placebo <- ifelse(is.na(dt$Placebo), "", dt$Placebo)
dt$se <- (log(dt$hi) - log(dt$est))/1.96
# Add blank column for the forest plot to display CI.
# Adjust the column width with space.
dt$` ` <- paste(rep(" ", 20), collapse = " ")
# Create confidence interval column to display
dt$`HR (95% CI)` <- ifelse(is.na(dt$se), "",
sprintf("%.2f (%.2f to %.2f)",
dt$est, dt$low, dt$hi))
View(dt)
- 绘图
# Define theme
tm <- forest_theme(base_size = 10,
refline_col = "red",
footnote_col = "#636363",
footnote_fontface = "italic")
p <- forest(dt[,c(1:3, 8:9)],
est = dt$est,
lower = dt$low,
upper = dt$hi,
sizes = dt$se,
ci_column = 4, #指定图绘制在第几列
ref_line = 1,
arrow_lab = c("Placebo Better", "Treatment Better"),
xlim = c(0, 4),
ticks_at = c(0.5, 1, 2, 3),
footnote = "This is the demo data. Please feel free to change\nanything you want.",
theme = tm)
# Print plot
plot(p)