ggobi / ggally

R package that extends ggplot2
http://ggobi.github.io/ggally/
588 stars 118 forks source link

Any interest in a `ticks` argument to `ggcorr`? #425

Open nickp60 opened 3 years ago

nickp60 commented 3 years ago

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 commented 3 years ago

@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 commented 1 year ago

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