Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions R/corrplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ corrplot = function(corr,
method = c('circle', 'square', 'ellipse', 'number', 'shade', 'color', 'pie'),
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),
mar = c(0, 0, 0, 0), del.lead.zero = FALSE,

addgrid.col = NULL, addCoef.col = NULL, addCoefasPercent = FALSE,

Expand Down Expand Up @@ -323,6 +323,12 @@ corrplot = function(corr,
stop('Need a matrix or data frame!')
}

# logical of whether leading zero is dropped from numbers generated from 'method = "number"' and 'addCoef.col'
if (del.lead.zero == TRUE) {
del.lead.zero = function(val) {sub("^(-?)0.", "\\1.", sprintf("%.2f", val)) }}
else if (del.lead.zero == FALSE) {
del.lead.zero = function(val){val}}

# select grid color automatically if not specified
if (is.null(addgrid.col)) {
addgrid.col = switch(method, color = NA, shade = NA, 'grey')
Expand Down Expand Up @@ -704,7 +710,7 @@ corrplot = function(corr,
if (method == 'number' && plotCI == 'n') {
x = (DAT - int) * ifelse(addCoefasPercent, 100, 1) / zoom
text(Pos[, 1], Pos[, 2], font = number.font, col = col.fill,
labels = format(round(x, number.digits), nsmall = number.digits),
labels = format(del.lead.zero(round(x, number.digits)), nsmall = number.digits),
cex = number.cex)
}

Expand Down Expand Up @@ -883,13 +889,14 @@ corrplot = function(corr,
## add numbers
if (!is.null(addCoef.col) && method != 'number') {
text(Pos[, 1], Pos[, 2], col = addCoef.col,
labels = format(
round(
(DAT - int) * ifelse(addCoefasPercent, 100, 1) / zoom,
number.digits
),
nsmall = number.digits
),


if (!is.null(addCoef.col) && method != 'number') {
text(Pos[, 1], Pos[, 2], col = addCoef.col,
labels = del.lead.zero(format(
round((DAT - int) * ifelse(addCoefasPercent, 100, 1) / zoom, number.digits),
nsmall = number.digits
)),
cex = number.cex, font = number.font)
}

Expand Down