diff --git a/R/ggcorrplot.R b/R/ggcorrplot.R index 77105af..2eef6cb 100644 --- a/R/ggcorrplot.R +++ b/R/ggcorrplot.R @@ -39,6 +39,9 @@ #' insig is "pch"). #' @param tl.cex,tl.col,tl.srt the size, the color and the string rotation of #' text label (variable names). +#' @param circle.scale to be used as a scaling factor for circles. Depending on +#' the output device it may be necessary to adjust this parameter. +#' @param mirror.axis.text logical value. If TRUE, axis text of plot is mirrored #' @return #' \itemize{ #' \item ggcorrplot(): Returns a ggplot2 @@ -105,12 +108,13 @@ ggcorrplot <- function (corr, method = c("square", "circle"), type = c("full", "lower", "upper"), ggtheme = ggplot2::theme_minimal, title = "", show.legend = TRUE, legend.title = "Corr", show.diag = FALSE, - colors = c("blue", "white", "red"), outline.color = "gray", - hc.order = FALSE, hc.method = "complete", + colors = c("blue", "white", "red"), colors.position = c(-1, 0, 1), + outline.color = "gray", hc.order = FALSE, hc.method = "complete", lab = FALSE, lab_col = "black", lab_size = 4, p.mat = NULL, sig.level = 0.05, insig = c("pch", "blank"), pch = 4, pch.col = "black", pch.cex = 5, - tl.cex = 12, tl.col = "black", tl.srt = 45) { + tl.cex = 12, tl.col = "black", tl.srt = 45, + circle.scale = 1, mirror.axis.text = F) { type <- match.arg(type) method <- match.arg(method) @@ -151,7 +155,7 @@ ggcorrplot <- function (corr, method = c("square", "circle"), corr$value <- corr$value * corr$signif } - corr$abs_corr <- abs(corr$value) * 10 + corr$abs_corr <- abs(corr$value) * 10 * circle.scale # Heatmap p <- @@ -161,23 +165,38 @@ ggcorrplot <- function (corr, method = c("square", "circle"), else if (method == "circle") { p <- p + ggplot2::geom_point(color = outline.color, shape = 21, ggplot2::aes_string(size = "abs_corr")) + - ggplot2::scale_size(range = c(4, 10)) + ggplot2::guides(size = FALSE) + ggplot2::scale_size(range = c(4, 10*circle.scale)) + ggplot2::guides(fill = guide_colorbar(barwidth = 8, barheight = 1, raster=TRUE, title=""), size = FALSE) } p <- - p + ggplot2::scale_fill_gradient2( - low = colors[1], high = colors[3], mid = colors[2], - midpoint = 0, limit = c(-1,1), space = "Lab", - name = legend.title + p + ggplot2::scale_fill_gradientn( + colours = colors, + values = colors.position, + limit = c(-1,1) ) + - ggtheme() + - ggplot2::theme( + ggtheme() + + if(mirror.axis.text) { + p <- + p + scale_x_discrete(position = "top") + + scale_y_discrete(position = "right") + + ggplot2::theme( + axis.text.x = ggplot2::element_text( + angle = tl.srt, vjust = 0, size = tl.cex, hjust = 0 + ), + axis.text.y = ggplot2::element_text(hjust=0, size = tl.cex), + legend.position = "bottom" + ) + } else { + p <- + p + ggplot2::theme( axis.text.x = ggplot2::element_text( angle = tl.srt, vjust = 1, size = tl.cex, hjust = 1 ), - axis.text.y = ggplot2::element_text(size = tl.cex) - ) + - ggplot2::coord_fixed() + axis.text.y = ggplot2::element_text(hjust=0, size = tl.cex) + ) + } + p <- p + ggplot2::coord_fixed() label <- round(corr[, "value"], 2) if (lab)