admin管理员组

文章数量:1123768

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:

For comparison, the official package example has a 'corr:**' result after the grouping

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

Share Improve this question edited 21 hours ago stefan 123k6 gold badges36 silver badges72 bronze badges Recognized by R Language Collective asked yesterday BreezeBreeze 1296 bronze badges 2
  • You just want the cells above the diagonal to be blank? – Eonema Commented yesterday
  • I apologize for the unclear content of my expression. I edited the question. It's not that the top of the diagonal is completely blank, but that some of the data ( corr:*** ) in it is not necessarily needed after grouping. – Breeze Commented yesterday
Add a comment  | 

1 Answer 1

Reset to default 1

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)
  ))
)

本文标签: rAdjustment of the correlation data labeling content in the upper right corner of ggpairsStack Overflow