From fb0646373b1da3e53554d1cc358f1c7862481be7 Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Thu, 17 Sep 2020 15:32:40 +0100 Subject: [PATCH] added scratch_plots/ggpairs_test.R to play with ggally for future --- scripts/plotting/scratch_plots/ggpairs_test.R | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 scripts/plotting/scratch_plots/ggpairs_test.R diff --git a/scripts/plotting/scratch_plots/ggpairs_test.R b/scripts/plotting/scratch_plots/ggpairs_test.R new file mode 100644 index 0000000..a8dfcb5 --- /dev/null +++ b/scripts/plotting/scratch_plots/ggpairs_test.R @@ -0,0 +1,65 @@ +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 + +)