[R] how to order variables on correlation plot
Ana Marija
@okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Fri Nov 6 15:07:50 CET 2020
Hello
I have data like this:
> head(my_data)
subjects DIABDUR HBA1C ESRD SEX AGE PHENO C1 C2
1 fam0110_G110 38 9.4 1 2 51 2 -0.01144980 0.002661140
2 fam0113_G113 30 12.5 1 2 40 2 -0.00502052 -0.000929061
3 fam0114_G114 23 8.4 2 2 45 2 -0.00251578 -0.003450950
4 fam0117_G117 37 9.0 2 2 46 2 -0.00704917 -0.000573325
5 fam0119_G119 22 9.4 1 1 46 1 0.00263433 0.001002370
6 fam0119_G120 NA NA 1 1 71 1 -0.00354795 -0.002045940
C3 C4 C5 C6 C7 C8
1 0.006028150 -0.00176795 -0.00148375 0.004543550 -0.006272170 -0.00535077
2 -0.000453402 -0.00192162 0.00416229 0.007868230 -0.001957670 -0.00473148
3 -0.001680860 -0.00620438 -0.00235092 0.000672831 -0.000278318 0.00647337
4 0.001436740 0.00155568 -0.00556147 -0.000386401 -0.006885350 0.00135539
5 -0.007396920 0.00326229 0.00355575 -0.011149400 0.009156510 0.00120833
6 0.004532050 0.00869862 -0.00113207 0.002244520 -0.002119220 0.00657587
C9 C10
1 0.00328111 -0.00113515
2 -0.00495790 0.00320201
3 0.00208591 -0.00874752
4 -0.00967934 0.00607760
5 0.00611030 0.00876190
6 -0.00990661 0.00635349
I am plotting it with:
library(dplyr)
library(magrittr)
library(corrplot)
d=my_data %>% data.frame %>% set_rownames(.$subjects) %>% select(-subjects)
res <- cor(d, use = "complete.obs")
pdf("correlation.pdf")
corrplot(res, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 45)
dev.off()
and I am getting the plot in attach. How to make it so that my
variables are shown on the plot in the order they are in my_data data
frame?
Thanks
Ana
More information about the R-help
mailing list