I have the following sample data and would like to left align all columns with text except for the column with “Direction of effect size from other study”.
df <- tibble(Outcome="CAD",
Exposure="CpG",
Gene = "XYZ",
"Direction of effect size from other study" ="+",
OR = 0.93,
OR_loci = 0.90,
OR_upci = 0.96,
"OR (95% CIs)" = "0.93 (0.90, 0.96)",
" " = " ")
I applied the following settings for 1) the general aesthetic, 2) the forest plot, and 3) later edits.
# _______________________________ 1: general aesthetic _______________________________ #
tm <- forest_theme(base_size = 10, # set text size
refline_col = "#969696", # colour of OR = 1 line
refline_lty = 'solid', # default is "dashed"
ci_lwd = 1.9, # line width of confidence intervals
ci_Theight = 0.2, # specifies height of T end of CIs / 'whiskers'
core=list(bg_params=list(fill=c(rep('#ffffff',length.out=1)))),#2
title_just = 'center', # centres the title
arrow_type = "closed",
legend_name = 'Method',
ci_col = '#440154',
arrow_label_just = "end",
core= list(padding=unit(c(4,3), 'mm')),
colhead=list(fg_params=list(hjust=0.5, x=0.5)) # centre align
# _______________________________ 2: forest plot _______________________________ #
p <- forest(df[,c(1:4,9,8)],
est = df$OR,
lower = df$OR_loci,
upper = df$OR_upci,
ci_column = 5, # the column where you want your forest plot
ref_line = 1,
ticks_at = c(0.9,0.95,1,1.05),
xlab='OR',
xlim = c(0.9, 1.05),
arrow_lab = c("Protective effect", "Increases risk"),
theme=tm)
# _______________________________ 3: later edits _______________________________ #
# Adds a line under header
g <- add_border(p, part = "header", row = 0,
gp = gpar(lwd = 2))
g <- add_border(g, part = "header", row = 1,
gp = gpar(lwd = 2))
g <- add_border(g, part = "body",
row=1,
gp=gpar(lwd=1))
g <- add_border(g, part = "body",
row=7,
gp=gpar(lwd=2))
g <- edit_plot(g,
col=3,
part='body',
gp=gpar(fontface="italic"))
I realise that from 1) the text in the body is left aligned. To let the 4th column of the forest plot (Direction of effect size from other study) alone be centre-aligned, I attempted to add in a few lines of code in 3), but this changed nothing.
# my failed attempt
g1 <- edit_plot(g,
col=4,
part='body',
which = 'text',
gp= gpar(just='center'))
I would appreciate any pointers in the right direction.