[英]Add p-value and/or 95% CI in the text of a correlation matrix plot
是否可以通過向此代碼添加一些內容,在相關矩陣 plot 的文本中添加精確的 p 值和/或 95% CI,在提到點估計的位置旁邊?
我也歡迎使用其他包的解決方案。
ggpairs(baseline2, title="correlogram ")
去向
baseline2 <- structure(list(delta_bp = c(-21.5, 7, -17.5, -10.5, -21, -7.5,
4.5, 3, -9, 9, -22.5, -9.5), delta_bp_05 = c(-21.5, 0, 3, -13.5,
-13, -4, -16.5, -8, 5, -5, -12, 0.5), delta_bp_10 = c(-26.5,
1, -6, -10.5, -9, -3, -20.5, -10, 1, -6, -22, -0.5)), row.names = c(NA,
-12L), class = c("tbl_df", "tbl", "data.frame"), na.action = structure(c(`17` = 17L,
`27` = 27L, `32` = 32L), class = "omit"))
您可以通過"statistic"
選項使用ggally_statistic
upper
來提高並提供您自己的text_fn
。 您提供給text_fn
的 function 獲取數據列並且應該返回要顯示的文本字符串。 這里是將 p 值和置信區間添加到相關性中。 這可以根據您的喜好進行定制。
tf = function(x,y) {
ct <- cor.test(x, y)
sprintf("Corr: %0.2f, p: %0.3f\n95%% CI: (%0.2f to %0.2f)",
ct$estimate, ct$p.value, ct$conf.int[1], ct$conf.int[2])
}
ggpairs(baseline2, title="correlogram ",
upper=list(continuous=wrap("statistic",text_fn=tf,title=NULL, sep=NULL)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.