简体   繁体   中英

correlation plot in ggplot2 with different variables in x and y axis

I want to visualize this correlation matrix using ggplot2. Is it possible to make it like what ggpairs() did but has different variables in x and y axis?

round(cor(df_correlation),3)[c(1:5,58,61,66,67,70,71),72:77]

output:
                             Mastery_1 Mastery_2 Mastery_3 Mastery_4 Mastery_5 Mastery_6
Platform_joined                  0.273    -0.049     0.160     0.238     0.324     0.161
gender                           0.223     0.137    -0.076     0.235     0.097    -0.117
native_speaker                  -0.188    -0.511    -0.469    -0.263    -0.238     0.049
English_proficiency             -0.094    -0.411    -0.388    -0.310    -0.221     0.104
SC0                              0.453     0.442     0.391     0.497     0.453     0.261
end_Ask_qs                      -0.200    -0.338    -0.201    -0.226    -0.111     0.112
end_Review_notes                 0.211    -0.183     0.153     0.307     0.412     0.430
end_Study_regularly              0.012    -0.182     0.014     0.123     0.188     0.232
end_Listen_carefully             0.060    -0.590    -0.298    -0.059     0.017     0.211
end_Class_attendance             0.018    -0.143    -0.042    -0.250    -0.233    -0.057
end_Discussion_participation     0.056    -0.119     0.247    -0.076    -0.046     0.382

Thank you for any hint!

You only have correlation values here, which means you can only have the type of ggpairs panels with the correlation written on them - the other types such as boxplots and scatter plots require the full data set.

From the comments, it appears you want more of a ggcorrplot look:

library(tidyverse)

df_correlation %>%
  rownames_to_column() %>%
  pivot_longer(-1) %>%
  ggplot(aes(x = name, y = rowname, fill = value)) +
  geom_tile() +
  geom_text(aes(label = value)) +
  coord_equal() +
  scale_fill_gradient2(low = "blue3", mid = "white", high = "red3") +
  labs(x = NULL, y = NULL)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM