Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any interest in a ticks argument to ggcorr? #425

Open
nickp60 opened this issue Sep 28, 2021 · 2 comments
Open

Any interest in a ticks argument to ggcorr? #425

nickp60 opened this issue Sep 28, 2021 · 2 comments
Labels

Comments

@nickp60
Copy link

nickp60 commented Sep 28, 2021

Would having ticks in ggcorr plots help anyone else? With short names the plots are easy to read, but with longer names I find it difficult. I'm happy to try to submit a PR if there is interest. This is how I've been adding them manually

library(tidyverse)
library(patchwork
library(GGally)
set.seed(123)

# sample data
recoded_data <- matrix(rnorm(n=1000), ncol = 25)
 colnames(recoded_data) <-  sapply(1:ncol(recoded_data), function(x){paste0(sep="", collapse="", sample(c(letters, 1:9), size = 10, replace = T))})

# this is how much of an overhang happens on the left side of the tick, to connect to the variable name
taglen =.2

# here I manually make the data defining the little carets/ticks/Ts
tickdf <-rbind(
    data.frame(x=(1:(ncol(recoded_data)-1))-taglen ) %>%     mutate(y=x+taglen, xend=x+.7, yend=y),
    data.frame(y=2:ncol(recoded_data) ) %>%     mutate(x=y, yend=y-.5, xend=y)
  )

# this only would work well for right-justified labels; the nudge_x gives the spaces for the ticks
ggcorr(recoded_data,   hjust = 1, size = 4, color = "grey50", geom = "circle", nudge_x=-.5) + 
      geom_segment(data=tickdf, aes(x=x+1, y=y, xend=xend+1, yend=yend ))

image

... versus either of these (hjust of 1 and 0, respectively)

GGally::ggcorr(recoded_data,method=  c("pairwise", "spearman"),
    size = 4, color = "grey50", geom = "circle", hjust=1) + 
 GGally::ggcorr(recoded_data,method=  c("pairwise", "spearman"),
    size = 4, color = "grey50", geom = "circle", hjust=0)

image

@schloerke
Copy link
Member

@nickp60 This is much easier to read!

A PR is welcome!

Should we also display a message if hjust (and similar variables that wouldn't make sense) is supplied?

@DarioS
Copy link

DarioS commented Nov 2, 2023

Nonetheless, the left-most label remains truncated. The only safe way would be to put labels along the axes on the outside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants