Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function to add customizable rectangles to correlation plots #185

Closed
wants to merge 11 commits into from

Conversation

douglaswhitaker
Copy link

@douglaswhitaker douglaswhitaker commented Jun 19, 2021

A colleague (Nathan Hebert) and I found a need to add arbitrary rectangles to the plots produced by corrplot. The context for this is psychological testing: rather than placing rectangles around empirical clusters as corrplot currently can do, we wanted to place rectangles on corrplots of items around the scales to which they belonged. Moreover, we wanted to be able to place rectangles off the diagonal around sets of items from different scales for which examining the correlation would be of interest (e.g., if items from two scales should be correlated, the rectangle would direct the reader's attention to these correlations).

There are two different functions:

  • make_rect, which draws a single rectangle
  • make_all_rects, which draws all of the rectangles possible based on user-specified variable cutpoints (with logicals for controlling whether off-diagonal rectangles are drawn).

We believe that this would be a useful pair of functions for users of the corrplot package who wish to examine the correlations either among known sets of variables or among variables that are hypothesized to have certain relationships - it has certainly been for us when producing reports in the area of psychological measurement. The .Rd files include examples of the use of these functions.

Please let me know if you have any questions. I'm not sure if these functions are of interest to you; if they are not, I can include them in a small R package I maintain as "Enhances" for corrplot.

P.S. I don't do many pull requests on GitHub, so apologies if I didn't quite do it right. We originally wrote these functions for version 0.85 master so there are some extra commits in there I guess.

Nathan-Hebert and others added 11 commits June 27, 2020 18:27
Fix Lijian's feedback: top margin too small
Fix top margin when type is 'lower'
update readme, delete unnessary things
Make the correlation coefficients adding on the graph is before param…
Merge branch 'master' into RectangleAddition

# Conflicts:
#	DESCRIPTION
@taiyun
Copy link
Owner

taiyun commented Jun 20, 2021

Thanks. @douglaswhitaker @NathanHebertMSVU

I will read your thoughts and code in a few days:)

@taiyun
Copy link
Owner

taiyun commented Jun 22, 2021

I revised corrRect() function. It can draw customizable rectangles now.

Update the latest version from Github, and run examples:

M <- cor(mtcars)
f=corrplot(M, order = "AOE")
r=rbind(c('gear', 'wt', 'qsec', 'carb'),
        c('wt', 'gear', 'carb', 'qsec'))
corrRect(namesMat=r, corrRes=f)

f=corrplot(M, method = "circle", order = "AOE", type='lower')
r=c('gear', 'carb', 'qsec', 'wt')
corrRect(namesMat=r, corrRes=f)

@taiyun taiyun closed this Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants