Base R solution to a forest table.
Read data for reprex using datapasta/data.table.
hi <- data.table::data.table(
Label = c("Employed less than 10 hours",
"Employed 10-19 hours","Employed 20-29 hours",
"Employed 30+ hours","Student parent","Student of color",
"Non-straight","Rents from a non-family member",
"Impacted by Camp Fire","Awareness of Services",
"Butte County Resident"),
Variable = c(NA,NA,NA,NA,
"student parent","nonwhite","sexualmin","rentdummy","CFImpact",
"services index","buttecountyres"),
Odds.Ratio = c(1.552445,1.941582,2.750768,
3.657031,1.17805,1.655103,1.542991,1.675287,2.893494,
0.881908,1.220567),
LB.CI = c(0.856855,1.204622,1.637697,
1.915008,0.4558084,1.16177,0.9406359,0.98844,1.94611,
0.7957599,0.7723993),
UB.CI = c(2.81271,3.129396,4.620345,
6.983721,3.044707,2.357926,2.531076,2.839409,4.302072,
0.9773825,1.928774)
)
# extract data
nvar <- NROW(hi)
est <- hi$Odds.Ratio
lcl <- hi$LB.CI
ucl <- hi$UB.CI
# extract labels
var.names <- hi$Label
est.t <- sprintf("%.2f", round(est,2))
lcl.t <- sprintf("%.2f", round(lcl,2))
ucl.t <- sprintf("%.2f", round(ucl,2))
or.text <- paste0(est.t, " (", lcl.t, ",", ucl.t, ")")
xlim <- c(0, 7)
y <- nvar:1
par(mar=c(4, 13, 0.5, 10))
plot.new()
plot.window(xlim=xlim, ylim=c(0.5, nvar+1.5), xlab="a")
points(x=est, y=y, pch=17)
axis(1, at=seq(0.5, max(xlim), by=.5))
arrows(lcl, y, ucl, y, code=3, length=0.05, angle=90)
segments(1, 0, 1, nvar+.5, col="grey")
mtext(var.names, at=y, adj=1, side=2, las=2)
mtext("Measure", at=nvar+1, adj=1, side=2, las=2,
cex=1.5, font=2)
mtext(or.text, at=y, adj=0, side=4, las=2)
mtext("OR (95% CI)", at=nvar+1, adj=0, side=4, las=2,
cex=1.5, font=2)
sessionInfo()
## R version 4.0.0 (2020-04-24)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18362)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United States.1252
## [2] LC_CTYPE=English_United States.1252
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] compiler_4.0.0 magrittr_1.5 tools_4.0.0 htmltools_0.4.0
## [5] yaml_2.2.1 Rcpp_1.0.4.6 stringi_1.4.6 rmarkdown_2.3
## [9] data.table_1.12.8 knitr_1.28 stringr_1.4.0 xfun_0.14
## [13] digest_0.6.25 rlang_0.4.6 evaluate_0.14