2026年4月10日 研究日志¶
研究内容:为之前获得的生存分析数据绘制森林图。具体数据暂时不能公开,绘图用的代码如下:
In [ ]:
library(here)
library(forestplot)
library(stringr)
library(dplyr)
save.image(file = 'forest_plot_20260410.RData')
load(file = 'forest_plot_20260410.RData')
# -------------------- DATA Input --------------------
path <- here("COPD10_mace_corrected_results_table_Main_Analysis.csv")
raw_data <- read.csv(path)
# -------------------- DATA Clean --------------------
# for select the data which needed to be presentation
raw_data <- raw_data %>%
dplyr::filter(!Outcome %in% c("ARF", "ICU", "HF*", "Pneumonia"))
# below is a standard pipeline
clean_data <- str_match(raw_data$aHR..95..CI., "([0-9\\.]+) \\(([0-9\\.]+), ([0-9\\.]+)\\)")
plot_data <- data.frame(
mean = as.numeric(clean_data[,2]),
lower = as.numeric(clean_data[,3]),
upper = as.numeric(clean_data[,4])
)
table_text <- cbind(
c("Outcome", raw_data$Outcome),
c("aHR (95% CI)", raw_data$aHR..95..CI.)
)
forestplot(
labeltext = table_text,
mean = c(NA, plot_data$mean), # First row is title -> NA
lower = c(NA, plot_data$lower),
upper = c(NA, plot_data$upper),
zero = 1, # HR baseline = 1
clip = c(0.4, 1.0),
xticks = c(0.4, 0.6, 0.8, 1.0),
is.summary = c(TRUE, rep(FALSE, nrow(raw_data))), # bold title
boxsize = 0.2,
vertices = TRUE,
col = fpColors(box = "royalblue", line = "darkblue", zero = "gray50"),
xlab = "Adjusted Hazard Ratio",
txt_gp = fpTxtGp(label = gpar(cex = 0.9), ticks = gpar(cex = 0.8))
)
注:以上代码并非最终版本,仅是今日工作的总结。
今天编程的时候犯了一个尴尬的错误:我忘记显式引用 dplyr::filter() 了,结果就是 Error: object 'Outcome' not found,找了半天数据问题才想起函数冲突这回事。·
给大家提个醒,别忘记这回事。昨天到外地的简短出差安排的时间太紧了,现在还是好累,今天打算就此休息了,下周一再见吧各位!