Skip to content

corrRect does not work with type = "upper" #289

@AlexisDerumigny

Description

@AlexisDerumigny

Hello,

Thanks for the package it is very useful!

When working with the full correlation matrix, I can add corrRect elements such as this:

library(corrplot)

data(mtcars)
M = cor(mtcars)

r = rbind(c('gear', 'wt', 'qsec', 'carb'),
          c('wt', 'gear', 'carb', 'qsec'))
corrplot(M, order = 'AOE') -> p
corrRect(p, namesMat = r)
Image

but this does not work with type = "upper":

r = rbind(c('gear', 'wt', 'qsec', 'carb'),
          c('wt', 'gear', 'carb', 'qsec'))
corrplot(M, order = 'AOE', type = "upper") -> p
corrRect(p, namesMat = r)

returns the error:

Error in getCharXY(namesMat[, 1:2, drop = FALSE], corrPos) : 
  gear, wt paired X-Y names were not found!

I tried to do this manually:

r = rbind(c('gear', 'wt', 'qsec', 'carb'),
          c('wt', 'gear', 'carb', 'qsec'))
corrplot(M, order = 'AOE', type = "upper")
rect(xleft = 6.5, ybottom = 6.5, xright = 11.5, ytop = 11.5,
     border = "black", lwd = 2)

but the rectangle is only partially drawn (maybe akin to #259 )

Image

I manage to solve this manually by enlarging the window. So this is fixed for my case, but I thought this could be interesting for someone else who would have the same issue.

plot.new()

plot.window(xlim = c(0, 13), ylim = c(0, 13),
            asp = 1, xaxs = 'i', yaxs = 'i')

r = rbind(c('gear', 'wt', 'qsec', 'carb'),
          c('wt', 'gear', 'carb', 'qsec'))
corrplot(M, order = 'AOE', type = "upper", add = TRUE)
rect(xleft = 6.5, ybottom = 6.5, xright = 11.5, ytop = 11.5,
     border = "black", lwd = 2)
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions