|
152 | 152 | #' |
153 | 153 | #' @param sig.level Significant level, if the p-value in \code{p-mat} is bigger |
154 | 154 | #' than \code{sig.level}, then the corresponding correlation coefficient is |
155 | | -#' regarded as insignificant. |
| 155 | +#' regarded as insignificant. If \code{insig} is \code{"label_sig"}, this may |
| 156 | +#' be an increasing vector of significance levels, in which case \code{pch} |
| 157 | +#' will be used once for the highest p-value interval and multiple times |
| 158 | +#' (e.g. "*", "**", "***") for each lower p-value interval. |
156 | 159 | #' |
157 | 160 | #' @param insig Character, specialized insignificant correlation coefficients, |
158 | | -#' \code{"pch"} (default), \code{"p-value"}, \code{"blank"} or \code{"n"}. If |
159 | | -#' \code{"blank"}, wipe away the corresponding glyphs; if \code{"p-value"}, |
160 | | -#' add p-values the corresponding glyphs; if \code{"pch"}, add characters (see |
161 | | -#' \code{pch} for details) on corresponding glyphs; if \code{"n"}, don't take |
162 | | -#' any measures. |
| 161 | +#' \code{"pch"} (default), \code{"p-value"}, \code{"blank"}, \code{"n"}, or |
| 162 | +#' \code{"label_sig"}. If \code{"blank"}, wipe away the corresponding glyphs; |
| 163 | +#' if \code{"p-value"}, add p-values the corresponding glyphs; |
| 164 | +#' if \code{"pch"}, add characters (see \code{pch} for details) on |
| 165 | +#' corresponding glyphs; if \code{"n"}, don't take any measures; if |
| 166 | +#' \code{"label_sig"}, mark significant correlations with pch |
| 167 | +#' (see \code{sig.level}). |
163 | 168 | #' |
164 | 169 | #' @param pch Add character on the glyphs of insignificant correlation |
165 | 170 | #' coefficients(only valid when \code{insig} is \code{"pch"}). See |
@@ -256,7 +261,7 @@ corrplot <- function(corr, |
256 | 261 | shade.lwd = 1, shade.col = "white", |
257 | 262 |
|
258 | 263 | p.mat = NULL, sig.level = 0.05, |
259 | | - insig = c("pch", "p-value", "blank", "n"), |
| 264 | + insig = c("pch", "p-value", "blank", "n", "label_sig"), |
260 | 265 | pch = 4, pch.col = "black", pch.cex = 3, |
261 | 266 |
|
262 | 267 | plotCI = c("n", "square", "circle", "rect"), |
@@ -791,26 +796,62 @@ corrplot <- function(corr, |
791 | 796 | pos.pNew <- getPos.Dat(p.mat)[[1]] |
792 | 797 | pNew <- getPos.Dat(p.mat)[[2]] |
793 | 798 |
|
794 | | - ind.p <- which(pNew > sig.level) |
795 | | - p_inSig <- length(ind.p) > 0 |
| 799 | + if (insig == "label_sig") { |
| 800 | + |
| 801 | + # Unless another character is specified, mark sig with * |
| 802 | + if(!is.character(pch)) |
| 803 | + pch <- "*" |
| 804 | + |
| 805 | + place_points <- function(sig.locs, point) |
| 806 | + text(pos.pNew[,1][sig.locs], pos.pNew[,2][sig.locs], |
| 807 | + labels = point, col = pch.col, cex = pch.cex, lwd = 2) |
| 808 | + |
| 809 | + if (length(sig.level) == 1) { |
| 810 | + place_points(sig.locs = which(pNew < sig.level), point = pch) |
| 811 | + |
| 812 | + } else { |
| 813 | + l <- length(sig.level) |
| 814 | + for (i in seq_along(sig.level)) { |
| 815 | + iter <- l + 1 - i |
| 816 | + pchTmp <- paste(rep(pch, i), collapse = "") |
| 817 | + if(i == length(sig.level)) { |
| 818 | + locs <- which(pNew < sig.level[iter]) |
| 819 | + if (length(locs)) |
| 820 | + place_points(sig.locs = locs, point = pchTmp) |
| 821 | + } else { |
| 822 | + locs <- which(pNew < sig.level[iter] & pNew > sig.level[iter - 1]) |
| 823 | + if(length(locs)) |
| 824 | + place_points(sig.locs = locs, point = pchTmp) |
| 825 | + } |
| 826 | + |
| 827 | + } |
| 828 | + } |
796 | 829 |
|
797 | | - if (insig == "pch" && p_inSig) { |
798 | | - points(pos.pNew[,1][ind.p], pos.pNew[,2][ind.p], |
799 | | - pch = pch, col = pch.col, cex = pch.cex, lwd = 2) |
800 | | - } |
| 830 | + } else { |
801 | 831 |
|
802 | | - if (insig == "p-value" && p_inSig) { |
803 | | - text(pos.pNew[,1][ind.p], pos.pNew[,2][ind.p], |
804 | | - round(pNew[ind.p],2), col = pch.col) |
805 | | - } |
| 832 | + ind.p <- which(pNew > sig.level) |
| 833 | + p_inSig <- length(ind.p) > 0 |
| 834 | + |
| 835 | + if (insig == "pch" && p_inSig) { |
| 836 | + points(pos.pNew[,1][ind.p], pos.pNew[,2][ind.p], |
| 837 | + pch = pch, col = pch.col, cex = pch.cex, lwd = 2) |
| 838 | + } |
806 | 839 |
|
807 | | - if (insig == "blank" && p_inSig) { |
808 | | - symbols(pos.pNew[,1][ind.p], pos.pNew[,2][ind.p], inches = FALSE, |
809 | | - squares = rep(1, length(pos.pNew[,1][ind.p])), |
810 | | - fg = addgrid.col, bg = bg, add = TRUE) |
| 840 | + if (insig == "p-value" && p_inSig) { |
| 841 | + text(pos.pNew[,1][ind.p], pos.pNew[,2][ind.p], |
| 842 | + round(pNew[ind.p],2), col = pch.col) |
| 843 | + } |
| 844 | + |
| 845 | + if (insig == "blank" && p_inSig) { |
| 846 | + symbols(pos.pNew[,1][ind.p], pos.pNew[,2][ind.p], inches = FALSE, |
| 847 | + squares = rep(1, length(pos.pNew[,1][ind.p])), |
| 848 | + fg = addgrid.col, bg = bg, add = TRUE) |
| 849 | + } |
811 | 850 | } |
812 | 851 | } |
813 | 852 |
|
| 853 | + |
| 854 | + |
814 | 855 | if (cl.pos != "n") { |
815 | 856 | colRange <- assign.color(dat = cl.lim2) |
816 | 857 | ind1 <- which(col == colRange[1]) |
|
0 commit comments