Skip to content

Commit

Permalink
Merge pull request #258 from taiyun/dev
Browse files Browse the repository at this point in the history
rename parameter
  • Loading branch information
taiyun authored Aug 31, 2022
2 parents c951351 + f4dac70 commit 0497ad6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: corrplot
Type: Package
Title: Visualization of a Correlation Matrix
Version: 0.93
Date: 2022-08-29
Date: 2022-08-31
Authors@R: c(
person('Taiyun', 'Wei', email = 'weitaiyun@gmail.com', role = c('cre', 'aut')),
person('Viliam', 'Simko', email = 'viliam.simko@gmail.com', role = 'aut'),
Expand Down
3 changes: 1 addition & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

* Fix #247: `addgrid.col` and `bg` don't work in mixed plot. (thanks, @ZoomMan91)
* Fix #246: using `insig = "n"` and `p.mat` sometimes causes an error. (thanks, @Sumidu)
* Fix #255: add new parameter `ignoreSign`, whether or not to ignore matrix values' sign when assigning colors for non-corr matrix.

* Fix #255: add new parameter `transKeepSign`, whether or not to keep matrix values' sign when transforming non-corr matrix.

# corrplot 0.92

Expand Down
42 changes: 23 additions & 19 deletions R/corrplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
#' are still distributed uniformly in [-1, 1], it only affect the display
#' on color-legend.
#'
#' @param is.corr Logical, whether the input matrix is a correlation matrix or
#' not. We can visualize the non-correlation matrix by setting
#' \code{is.corr = FALSE}.
#'
#'
#' @param bg The background color.
#'
Expand Down Expand Up @@ -99,15 +103,6 @@
#' valid when \code{addrect} is equal or greater than 1.
#'
#'
#' @param is.corr Logical, whether the input matrix is a correlation matrix or
#' not. We can visualize the non-correlation matrix by setting
#' \code{is.corr = FALSE}.
#'
#' @param ignoreSign Logical, whether or not to ignore matrix values' sign when assigning colors
#’ for non-corr matrix.
#' Only valid when \code{is.corr = FALSE}. The default value is \code{FALSE}.
#'
#'
#' @param tl.pos Character or logical, position of text labels. If character, it
#' must be one of \code{'lt'}, \code{'ld'}, \code{'td'}, \code{'d'} or
#' \code{'n'}. \code{'lt'}(default if \code{type=='full'}) means left and top,
Expand Down Expand Up @@ -169,6 +164,12 @@
#'
#' @param shade.col The color of shade line.
#'
#' @param transKeepSign Logical, whether or not to keep matrix values' sign when
#' transforming non-corr matrix for plotting.
#' Only valid when \code{is.corr = FALSE}. The default value is \code{TRUE}.
#'
#' NOTE: If \code{FALSE},the non-corr matrix will be
#'
#' @param p.mat Matrix of p-value, if \code{NULL}, parameter \code{sig.level},
#' \code{insig}, \code{pch}, \code{pch.col}, \code{pch.cex} are invalid.
#'
Expand Down Expand Up @@ -266,8 +267,8 @@
#' @export
corrplot = function(corr,
method = c('circle', 'square', 'ellipse', 'number', 'shade', 'color', 'pie'),
type = c('full', 'lower', 'upper'), col = NULL, col.lim = NULL, bg = 'white',
title = '', add = FALSE, diag = TRUE, outline = FALSE,
type = c('full', 'lower', 'upper'), col = NULL, col.lim = NULL, is.corr = TRUE,
bg = 'white', title = '', add = FALSE, diag = TRUE, outline = FALSE,
mar = c(0, 0, 0, 0),

addgrid.col = NULL, addCoef.col = NULL, addCoefasPercent = FALSE,
Expand All @@ -277,8 +278,6 @@ corrplot = function(corr,
'average', 'mcquitty', 'median', 'centroid'),
addrect = NULL, rect.col = 'black', rect.lwd = 2,

is.corr = TRUE, ignoreSign = FALSE,

tl.pos = NULL, tl.cex = 1,
tl.col = 'red', tl.offset = 0.4, tl.srt = 90,

Expand All @@ -290,6 +289,8 @@ corrplot = function(corr,
addshade = c('negative', 'positive', 'all'),
shade.lwd = 1, shade.col = 'white',

transKeepSign = TRUE,

p.mat = NULL, sig.level = 0.05,
insig = c('pch', 'p-value', 'blank', 'n', 'label_sig'),
pch = 4, pch.col = 'black', pch.cex = 3,
Expand Down Expand Up @@ -327,6 +328,10 @@ corrplot = function(corr,
addgrid.col = switch(method, color = NA, shade = NA, 'grey')
}

if(!is.corr & !transKeepSign & method %in% c('circle', 'square', 'ellipse', 'shade', 'pie')) {
stop("method should not be in c('circle', 'square', 'ellipse', 'shade', 'pie') when transKeepSign = FALSE")
}

# Issue #142
# checks for all values that are not missing
if (any(corr[!is.na(corr)] < col.lim[1]) || any(corr[!is.na(corr)] > col.lim[2])) {
Expand Down Expand Up @@ -389,15 +394,14 @@ corrplot = function(corr,
warning('col.lim interval too wide, please set a suitable value')
}

# all negative or positive or NOT keepSign, trans to [0, 1]
if (c_max <= 0 | c_min>=0 | ignoreSign) {
# all negative or positive or NOT transkeepSign, trans to [0, 1]
if (c_max <= 0 | c_min>=0 | !transKeepSign) {
intercept = - col.lim[1]
zoom = 1 / (diff(col.lim))


if(col.lim[1] * col.lim[2] < 0) {
warning('col.lim interval not suitable to the matrix')
}
#if(col.lim[1] * col.lim[2] < 0) {
# warning('col.lim interval not suitable to the matrix')
#}

}

Expand Down
21 changes: 12 additions & 9 deletions man/corrplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions vignettes/corrplot-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,15 @@ corrplot(N1, is.corr = FALSE, col.lim = c(20, 30), method = 'color', tl.pos = 'n
## matrix in [-15, 10]
N2 = matrix(runif(80, -15, 10), 8)
## using sequential colors and ignore matrix values' sign when assigning colors
corrplot(N2, is.corr = FALSE, ignoreSign = TRUE, method = 'color', col.lim = c(-15, 10),
tl.pos = 'n', col = COL1("YlOrBr"), cl.pos = 'b', addCoef.col = 'grey50')
## using sequential colors, transKeepSign = FALSE
corrplot(N2, is.corr = FALSE, transKeepSign = FALSE, method = 'color', col.lim = c(-15, 10),
tl.pos = 'n', col = COL1('YlGn'), cl.pos = 'b', addCoef.col = 'grey50')
## using diverging colors and don't ignore matrix values' sign when assigning colors
## using diverging colors, transKeepSign = TRUE (default)
corrplot(N2, is.corr = FALSE, col.lim = c(-15, 10),
tl.pos = 'n', col = COL2('PiYG'), cl.pos = 'b', addCoef.col = 'grey50')
## using diverging colors
corrplot(N2, is.corr = FALSE, method = 'color', col.lim = c(-15, 10), tl.pos = 'n',
col = COL2('PiYG'), cl.pos = 'b', addCoef.col = 'grey50')
```
Expand Down

0 comments on commit 0497ad6

Please sign in to comment.