0

I have a large dataset with different numeric and factorial data. Doing a correlation plot with ggcorr(data) gives me an interesting graph, but half of it is useless to me because I just need to correlate between the descriptive and measures data. There would give a 5*4 square instead of a triangle with a length of 9 with my data. Is there a way to do this? And is there a way to add the P values as stars?

A short dataset which looks similar to mine:

State <-as.factor(c("land", "loc2", "loc2", "loc3"))
Age <- c(20, 24, 22, 49)
Education<- as.factor(c(2, 2, 3, 1))
AreaHill <- c(NA, 22, 18, 2)
AreaPlain <-c(1, 3, NA, NA)
Style <-as.factor(c("s2", "s3", "s2", "s2"))
descriptive <-cbind(State, Age, Education, AreaHill, AreaPlain, Style)

Measure1 <-c(2, 4, 2, 2)
Measure2 <-c(4, 4, 2, 5)
Measure3 <-c(2, 3, 1, 1)
Measure4 <-c(2, 1, 2, 2)

measures <- cbind(Measure1, Measure2, Measure3, Measure4)
data <- cbind(State, Age, Education, AreaHill, AreaPlain, Style, Measure1, Measure2, Measure3, Measure4)

library(GGally)
ggcorr(data)

``` Here is what I have so far
[The correlations now, as a triangle][1]
and here is what I want to have: correlations between categories, but not among them, as well as the p. value as a star (or anything else).
[The potential image with correlation between some categories but without correlation among them][2]


  [1]: https://i.stack.imgur.com/a5Uib.jpg
  [2]: https://i.stack.imgur.com/cLUSP.jpg
zx8754
  • 52,746
  • 12
  • 114
  • 209
Sisymbrium
  • 11
  • 3
  • `State` is missing in your example... So you want to add the p-value in *-notation to each square? And why do you want the whole square? The matrix is symmetric. – Christoph Nov 05 '20 at 15:07
  • It is not clear what you're looking for. If what you're looking for is a subset of the correlation matrix, you could subset your data before calling `ggcorr` to only include the columns of interest? – Oliver Nov 05 '20 at 15:07
  • I am interested in all the correlations between "the descriptive" and "measures", not among themselves. This would end up in a rectangular shape, with the "descriptive" in one axis and "measures" in the other. Is it clear like this? @Christoph State added – Sisymbrium Nov 05 '20 at 15:46
  • I guess you need to subset or create your own plot. – Christoph Nov 05 '20 at 17:48
  • I'm not sure if ggcorr will work in this instance as it is plotting all variables in the dataset that is supplied. Have a look at the plot.matrix package found here: https://cran.r-project.org/web/packages/plot.matrix/vignettes/plot.matrix.html It sounds like you'll need to construct your own matrix after obtaining the correlation values you're interested in. The picture of the factor analysis visual in the link above sounds somewhat like what you're describing. For the "***" entries, try entering these as text for displaying the matrix entries. – Jonni Nov 10 '20 at 04:26
  • @Jonni It works with the package plot.matrix to show not all correlations, but only some with some others. However the labels get lost on the way. Am I doing something wrong, or is there a workaround? – Sisymbrium Nov 11 '20 at 10:44

1 Answers1

1

With the package plot.matrix shown by @Jonni, a correlation matrix not showing all combinations can be made

library(plot.matrix)
corr.data<-correlate(data) # make all the correlations, as before
square <-corr.data[c(2:7),c(8:11)]# cut out the ones I am interested in
square <- as.matrix(square) # it works only as a matrix
plot(square) ## now it works, when as a matrix
plot(as.cor(square), reorder = F) # plot as correlation

now I have to again add the rownames,

rownames(square)<- c("State", "Age", "Education", "AreaHill", "AreaPlain", "Style")
plot(as.cor(square), las=2, reorder=F) ## and it gives me the plot with the correlated aspects named
Sisymbrium
  • 11
  • 3