Skip to content

Commit c336f9d

Browse files
authored
Merge pull request #80 from vsimko/master
- parameter `win.asp` (issue #80) - parameter `outline` combined with `method="pie"` (issue #18) - updated vignette - more unit tests
2 parents 38f852d + 2b55d68 commit c336f9d

11 files changed

Lines changed: 284 additions & 155 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
Package: corrplot
22
Type: Package
33
Title: Visualization of a Correlation Matrix
4-
Version: 0.80
5-
Date: 2016-11-14
4+
Version: 0.81
5+
Date: 2017-02-07
66
Author: Taiyun Wei, Viliam Simko
77
Suggests:
8-
seriation,
98
knitr,
10-
Cairo,
119
testthat
1210
Maintainer: Taiyun Wei <weitaiyun@gmail.com>
1311
Description: A graphical display of a correlation matrix or general matrix.
@@ -16,4 +14,4 @@ License: GPL
1614
URL: https://github.com/taiyun/corrplot
1715
BugReports: https://github.com/taiyun/corrplot/issues
1816
VignetteBuilder: knitr
19-
RoxygenNote: 5.0.1
17+
RoxygenNote: 6.0.1

R/corrplot.R

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
#' principal diagonal.
4343
#'
4444
#' @param outline Logical or character, whether plot outline of circles, square
45-
#' and ellipse, or the color of these glyphs. If \code{outline} is
46-
#' \code{TRUE}, the default value is \code{"black"}.
45+
#' and ellipse, or the color of these glyphs. For pie, this represents the
46+
#' color of the circle outlining the pie. If \code{outline} is \code{TRUE},
47+
#' the default value is \code{"black"}.
4748
#'
4849
#' @param mar See \code{\link{par}}.
4950
#'
@@ -189,6 +190,9 @@
189190
#' @param na.label.col Color used for rendering \code{NA} cells. Default is
190191
#' \code{"black"}.
191192
#'
193+
#' @param win.asp Aspect ration for the whole plot. Value other than 1 is
194+
#' currently compatible only with methods "circle" and "square".
195+
#'
192196
#' @param \dots Additional arguments passing to function \code{text} for drawing
193197
#' text lable.
194198
#'
@@ -259,6 +263,7 @@ corrplot <- function(corr,
259263
plotCI = c("n", "square", "circle", "rect"),
260264
lowCI.mat = NULL, uppCI.mat = NULL,
261265
na.label = "?", na.label.col = "black",
266+
win.asp = 1,
262267
...)
263268
{
264269

@@ -271,6 +276,13 @@ corrplot <- function(corr,
271276
insig <- match.arg(insig)
272277
plotCI <- match.arg(plotCI)
273278

279+
# rescale symbols within the corrplot based on win.asp parameter
280+
if (win.asp != 1 && !(method %in% c("circle", "square"))) {
281+
stop("Parameter 'win.asp' is supported only for circle and square methods.")
282+
}
283+
asp_rescale_factor <- min(1, win.asp) / max(1, win.asp)
284+
stopifnot(asp_rescale_factor >= 0 && asp_rescale_factor <= 1)
285+
274286
if (!is.matrix(corr) && !is.data.frame(corr)) {
275287
stop("Need a matrix or data frame!")
276288
}
@@ -435,14 +447,14 @@ corrplot <- function(corr,
435447
ifelse(grepl("^[:=$]", s), parse(text = substring(s, 2)), s)
436448
}
437449

438-
newrownames <- sapply(
439-
rownames(corr)[(n + 1 - n2):(n + 1 - n1)], expand_expression)
450+
newrownames <- sapply(
451+
rownames(corr)[(n + 1 - n2):(n + 1 - n1)], expand_expression)
440452

441-
newcolnames <- sapply(
442-
colnames(corr)[m1:m2], expand_expression)
453+
newcolnames <- sapply(
454+
colnames(corr)[m1:m2], expand_expression)
443455

444-
DAT <- getPos.Dat(corr)[[2]]
445-
len.DAT <- length(DAT)
456+
DAT <- getPos.Dat(corr)[[2]]
457+
len.DAT <- length(DAT)
446458

447459
rm(expand_expression) # making sure the function is only used here
448460

@@ -478,14 +490,12 @@ corrplot <- function(corr,
478490

479491
if (isFALSE(outline)) {
480492
col.border <- col.fill
481-
}
482-
483-
if (isTRUE(outline)) {
493+
} else if (isTRUE(outline)) {
484494
col.border <- "black"
485-
}
486-
487-
if (is.character(outline)) {
495+
} else if (is.character(outline)) {
488496
col.border <- outline
497+
} else {
498+
stop("Unsupported value type for parameter outline")
489499
}
490500

491501
oldpar <- par(mar = mar, bg = "white")
@@ -500,7 +510,7 @@ corrplot <- function(corr,
500510
m2 + 0.5 + mm * cl.ratio * (cl.pos == "r"))
501511
ylim <- c(n1 - 0.5 - nn * cl.ratio * (cl.pos == "b"),
502512
n2 + 0.5 + ylabwidth)
503-
plot.window(xlim + c(-0.2,0.2), ylim + c(-0.2,0.2), asp = 1,
513+
plot.window(xlim + c(-0.2, 0.2), ylim + c(-0.2, 0.2), asp = 1,
504514
xaxs = "i", yaxs = "i")
505515
x.tmp <- max(strwidth(newrownames, cex = tl.cex))
506516
y.tmp <- max(strwidth(newcolnames, cex = tl.cex))
@@ -522,7 +532,7 @@ corrplot <- function(corr,
522532

523533
laboffset <- strwidth("W", cex = tl.cex) * tl.offset
524534
xlim <- c(m1 - 0.5 - xlabwidth - laboffset,
525-
m2 + 0.5 + mm * cl.ratio * (cl.pos == "r")) + c(-0.35,0.15)
535+
m2 + 0.5 + mm * cl.ratio * (cl.pos == "r")) + c(-0.35, 0.15)
526536
ylim <- c(n1 - 0.5 - nn * cl.ratio * (cl.pos == "b"),
527537
n2 + 0.5 + ylabwidth * abs(sin(tl.srt * pi / 180)) + laboffset)
528538
+ c(-0.15, 0.35)
@@ -533,21 +543,21 @@ corrplot <- function(corr,
533543
}
534544

535545
plot.window(xlim = xlim , ylim = ylim,
536-
asp = 1, xlab = "", ylab = "", xaxs = "i", yaxs = "i")
546+
asp = win.asp, xlab = "", ylab = "", xaxs = "i", yaxs = "i")
537547
}
538548

539549
## for: add = TRUE
540550
laboffset <- strwidth("W", cex = tl.cex) * tl.offset
541551

542-
## squares
552+
## background for the cells
543553
symbols(Pos, add = TRUE, inches = FALSE,
544-
squares = rep(1, len.DAT), bg = bg, fg = bg)
554+
rectangles = matrix(1, len.DAT, 2), bg = bg, fg = bg)
545555

546556
## circle
547557
if (method == "circle" && plotCI == "n") {
548-
symbols(Pos, add = TRUE, inches = FALSE,
549-
circles = 0.9 * abs(DAT) ^ 0.5 / 2,
550-
fg = col.border, bg = col.fill )
558+
symbols(Pos, add = TRUE, inches = FALSE,
559+
circles = asp_rescale_factor * 0.9 * abs(DAT) ^ 0.5 / 2,
560+
fg = col.border, bg = col.fill )
551561
}
552562

553563
## ellipse
@@ -556,7 +566,7 @@ corrplot <- function(corr,
556566
k <- seq(0, 2 * pi, length = length)
557567
x <- cos(k + acos(rho) / 2) / 2
558568
y <- cos(k - acos(rho) / 2) / 2
559-
return(cbind(rbind(x,y), c(NA, NA)))
569+
cbind(rbind(x,y), c(NA, NA))
560570
}
561571

562572
ELL.dat <- lapply(DAT, ell.dat)
@@ -606,7 +616,10 @@ corrplot <- function(corr,
606616

607617
## pie
608618
if (method == "pie" && plotCI == "n") {
609-
symbols(Pos, add = TRUE, inches = FALSE, circles = rep(0.5, len.DAT) * 0.85)
619+
620+
# Issue #18: Corrplot background circle
621+
symbols(Pos, add = TRUE, inches = FALSE,
622+
circles = rep(0.5, len.DAT) * 0.85, fg = col.border)
610623

611624
pie.dat <- function(theta, length = 100) {
612625
k <- seq(pi / 2, pi / 2 - theta, length = 0.5 * length * abs(theta) / pi)
@@ -663,7 +676,8 @@ corrplot <- function(corr,
663676
## square
664677
if (method == "square" && plotCI == "n") {
665678
symbols(Pos, add = TRUE, inches = FALSE,
666-
squares = abs(DAT) ^ 0.5, bg = col.fill, fg = col.border)
679+
squares = asp_rescale_factor * abs(DAT) ^ 0.5,
680+
bg = col.fill, fg = col.border)
667681
}
668682

669683
## color
@@ -673,8 +687,8 @@ corrplot <- function(corr,
673687
}
674688

675689
## add grid
676-
symbols(Pos, add = TRUE, inches = FALSE, bg = NA,
677-
squares = rep(1, len.DAT), fg = addgrid.col)
690+
symbols(Pos, add = TRUE, inches = FALSE, bg = NA, fg = addgrid.col,
691+
rectangles = matrix(1, nrow = len.DAT, ncol = 2) )
678692

679693
if (plotCI != "n") {
680694

@@ -693,7 +707,7 @@ corrplot <- function(corr,
693707
uppNew <- getPos.Dat(uppCI.mat)[[2]]
694708

695709
if (!method %in% c("circle", "square")) {
696-
stop("method shoud be circle or square if draw confidence interval!")
710+
stop("Method shoud be circle or square if drawing confidence intervals.")
697711
}
698712

699713
k1 <- (abs(uppNew) > abs(lowNew))

inst/CITATION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
bibentry("Manual",
22
title="R package 'corrplot': Visualization of a correlation matrix",
33
author="Taiyun Wei and Viliam Simko",
4-
year="2016",
5-
note="(Version 0.80)",
4+
year="2017",
5+
note="(Version 0.81)",
66
url="https://github.com/taiyun/corrplot",
77

88
textVersion =
99
paste("T. Wei and V. Simko (2016). ",
10-
"R package 'corrplot': Visualization of a correlation matrix (Version 0.80). ",
10+
"R package 'corrplot': Visualization of a correlation matrix (Version 0.81). ",
1111
"Available from https://github.com/taiyun/corrplot",
1212
sep=""),
1313

man/colorlegend.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/corrMatOrder.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/corrRect.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/corrRect.hclust.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/corrplot.Rd

Lines changed: 12 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/corrplot.mixed.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)