library(GGally)

# with outcome
ggpairs(my_corr_ps[1:(length(my_corr_ps)-1)]
        , upper = list(continuous = wrap('cor', method = "spearman"))
        , aes(colour = factor(my_corr_ps$duet_outcome), alpha = 0.4)
        , title="correlogram with ggpairs()") 

corr_data_plot_ps = my_corr_ps[1:(length(my_corr_ps)-1)]

my_fn <- function(data, mapping, ...){
  p <- ggplot(data = data, mapping = mapping) + 
    stat_density2d(aes(fill=..density..), geom="tile", contour = FALSE) +
    #scale_fill_gradientn(colours=rainbow(100))
  p
}

ggpairs(corr_data_plot_ps
        , lower=list(continuous=my_fn)
        , upper = list(continuous = wrap('cor', method = "spearman"))
        #, diag=list(continuous=wrap("barDiag", binwidth=100))
        #, upper=list(continuous=wrap('cor', method = "spearman"), sz=10, stars=FALSE))
)

panel.hist <- function(x, ...)
{
  usr <- par("usr"); on.exit(par(usr))
  par(usr = c(usr[1:2], 0, 1.5) )
  h <- hist(x, plot = FALSE)
  breaks <- h$breaks; nB <- length(breaks)
  y <- h$counts; y <- y/max(y)
  rect(breaks[-nB], 0, breaks[-1], y, col = "cyan", ...)
}

pairs(my_corr_ps[1:(length(my_corr_ps)-1)]
      , method = "spearman"
      , diag.panel = panel.hist
      , lower.panel = NULL)

      
  

#=============
source("my_pairs.panel.R")
my_pp(my_corr_ps[1:(length(my_corr_ps)-1)]
             , method = "spearman" # correlation method
             , hist.col = "grey" ##00AFBB
             , density = TRUE  # show density plots
             , ellipses = F # show correlation ellipses
             , stars = T
             , rug = F
             , breaks = "Sturges"
             , show.points = T
             , bg = c("#f8766d", "#00bfc4")[unclass(factor(my_corr_ps$duet_outcome))]
             , pch = 21
             , jitter = T
             #, alpha = .05
             #, points(pch = 19, col = c("#f8766d", "#00bfc4"))
             , cex = 3
             , cex.axis = 2.5
             , cex.labels = 2.1
             , cex.cor = 1
             , smooth = F
             
)
