When I use the ggpairs function in ggally, the result will always contain an “overall” extreme result of the data: corr:***. This is not always appropriate (needed) after analyzing the data grouping. I recently read an article with the same situation, and all I can think of at the moment is to export the PDF file and then process it. Does anyone have a more straightforward approach?
This figure comes from:https://www.nature.com/articles/s41559-023-02253-z
For comparison, the official package example has a 'corr:**' result after the grouping:
Here is one (hacky??) option which removes the title aka the overall correlation using title_args = list(x = NA, na.rm = TRUE)
, then fixes the position of the group correlations using the group_args=
argument of ggally_cor
.
Using a minimal reprex based on iris
:
library(ggplot2)
library(GGally)
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
dat <- iris[c(1:3, 5)]
names(dat) <- c(paste0("tars", 1:3), "Species")
ggpairs(
data = dat,
mapping = aes(color = Species),
columns = 1:3,
upper = list(continuous = wrap(
ggally_cor,
group_args = list(
y = I(seq(.2, .8, length.out = length(unique(dat$Species))))
),
title_args = list(x = NA, na.rm = TRUE)
))
)