colors - How to colourise some cell borders in R corrplot? -
i keep cells in attention making borders distinct else. parameter rect.col used colorise borders want colorise borders of cells (3,3) , (7,7), instance, halo color etc heat.colors(100) or rainbow(12). code
library("corrplot") library("psych") ids <- seq(1,11) m.cor <- cor(mtcars) colnames(m.cor) <- ids rownames(m.cor) <- ids p.mat <- psych::corr.test(m.cor, adjust = "none", ci = f) p.mat <- p.mat[["r"]] corrplot(m.cor, method = "color", type = "upper", tl.col = 'black', diag = true, p.mat = p.mat, sig.level = 0.0000005 ) fig. 1 output of top code without cell bordering, fig. 2 output after manually converting coordinates upper triangle artifact @ (10,1),
fig. 3 output window size fix
input: locations ids (3,3) , (7,7)
expected output: 2 cells borders marked on upper triangle
pseudocode
# ids must id.pairs # or list of 2 lists createborders <- function(id.pairs) { labbly(id.pairs,function(z){ x <- z$v1 y <- z$v2 rect(x+0.5, y+0.5, x+1.5, y+1.5) # user20650 }) } corrplot(...) # todo datastructure use there in function paired list of ids? createborders(ids.pairs) testing user20650's proposal
rect(2+0.5, 9+0.5, 3+0.5, 10+0.5, border="white", lwd=2) output in fig. 2. great have function this. assume have list of ids.
i think there wrong placement because (2,3),(9,10) leads point in (2,3),(2,3).
iterating user20650's proposal in chat
library("corrplot") library("psych") ids <- seq(1,11) m.cor <- cor(mtcars) colnames(m.cor) <- ids rownames(m.cor) <- ids p.mat <- psych::corr.test(m.cor, adjust = "none", ci = f) p.mat <- p.mat[["r"]] # chat of http://stackoverflow.com/q/40538304/54964 user20650 cb <- function(corrplot, ..., rectargs = list() ){ lst <- list(...) n <- ncol(corrplot) nms <- colnames(corrplot) colnames(corrplot) <- if(is.null(nms)) 1:ncol(corrplot) else nms xleft <- match(lst$x, colnames(corrplot)) - 0.5 ybottom <- n - match(lst$y, colnames(corrplot)) + 0.5 lst <- list(xleft=xleft, ybottom=ybottom, xright=xleft+1, ytop=ybottom+1) do.call(rect, c(lst, rectargs)) } plt <- corrplot(m.cor, method = "color", type = "upper", tl.col = 'black', diag = true, p.mat = p.mat, sig.level = 0.0000005 ) cb(plt, x=c(1, 3, 5), y=c(10, 7, 4), rectargs=list(border="white", lwd=3)) output 1 cell border marked in fig. 3.
expected output: 3 cell borders marked
restriction in fig. 2 approach
you have work coordinates first upper triangle. can call following output has artifact @ (10,1) in fig. 2
cb(plt, x=c(10, 7, 5), y=c(1, 3, 4), rectargs=list(border="white", lwd=3)) expected output: no artifact @ (10,1)
the cause of artifact can white background, occurs if border color red not cause. solution - fix window size , output in fig. 3
pdf("rplots.pdf", height=10, width=10) plt <- corrplot(m.cor, method = "color", type = "upper", tl.col = 'black', diag = true, p.mat = p.mat, sig.level = 0.0000005 ) cb(plt, x=c(10, 7, 5), y=c(1, 3, 4), rectargs=list(border="red", lwd=3)) dev.off() r: 3.3.1
os: debian 8.5
docs corrplot: here
my proposal still pseudocode mark.ids. found best have plt , mark.ids options of corrplotcellborders creates corrplot bordered wanted cells
mark.ids <- {x <- c(1), y <- c(2)} # todo pseudocode corrplotcellborders(plt, mark.ids) cb(plt, x, y, rectargs=list(border="red", lwd=3)) # chat of https://stackoverflow.com/q/40538304/54964 user20650 # createborders.r, test.createborders. cb <- function(corrplot, ..., rectargs = list() ){ # ... pass named vector of x , y names # upper x > y, lower x < y lst <- list(...) n <- ncol(corrplot) nms <- colnames(corrplot) colnames(corrplot) <- if(is.null(nms)) 1:ncol(corrplot) else nms xleft <- match(lst$x, colnames(corrplot)) - 0.5 ybottom <- n - match(lst$y, colnames(corrplot)) + 0.5 lst <- list(xleft=xleft, ybottom=ybottom, xright=xleft+1, ytop=ybottom+1) do.call(rect, c(lst, rectargs)) } corrplotcellborders <- function(plt, mark.ids) { x <- mark.ids$x y <- mark.ids$y cb(plt, x, y, rectargs=list(border="red", lwd=3)) } open
- how create
mark.idssuch can call itemsmark.ids$x,mark.ids$y? - integrate point order neutrality upper triangle here



Comments
Post a Comment