Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

correlation plot (with unique values) based on 2 variables

$
0
0

I have a dataframe like this:

df <- data.frame(
  "var1" = c("A", "A", "A", "B", "B", "C"),
  "var2" = c("B", "C", "D", "C", "D", "D"),
  "corr" = runif(6, -1, 1),
  "p_cat" = sample(1:3, 6, replace=T))
print(df)

As an example the dataframe is:

var1 var2 corr  p_cat
A     B   .76     1
A     C   .54     3
A     D  -.30     3
B     C   .11.    1
B     D   .56     2
C     D   .23     1

I'd like to have a plot like this:

enter image description here

library(corrplot) corrplot(M, method="circle")

where on each row and columns there are the var names (ie A, B, C). Indeed on the diagonal the correlation between one variable and itself is 1.

Moreover I'd like the circles of the plots to have this features:

  • the color of each circle has to be according to the legend on the left side of the plot (ie. the closer the Correlation value to 1, the darker the blue. The closer to -1, the redder)

  • the size of each circle has to have 1 out of 3 sizes - say small, medium and large - according to the value in the p_cat variable (ie. if the correlation between A and B is .89 and its p_cat is 3 then I'd see a blue large size circle).


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>