Hello,
This is about correlation analysis among factors.
The correlation analysis used to lots of study fields.
In my case, i used to analysis between microbiome and environmental factors.
We used "corplot" and "PerformanceAnalytics" in Rstudio.
You can follow up with following steps below.
1. Install Packages
#+++++++++++++++++++++++++Install Packages++++++++++++++++++++++++++++++++++++#
install.packages("corrplot")
install.packages("PerformanceAnalytics")
2. Run Packages
#++++++++++++++++++++++++++Load library+++++++++++++++++++++++++++++++++++++++#
library(corrplot)
library(PerformanceAnalytics)
3. Input data
#++++++++++++++++++++++++++Input data+++++++++++++++++++++++++++++++++++++++++#
test <- read.delim("clipboard", row.names=1) #엑셀에서 input format Ctrl+C
test <- t(test)
read.delim is calling your data from copied data frame in excel.
t() is command that change row and column.
If you called data like (2) format, you do not have to command change row and column.
See the below data format.
(1)
(2)
4. Calculate correlation
#+++++++++++++++++++++++++++ Calculate ++++++++++++++++++++++++++++++++++#
Correlation <- cor(test, use="pairwise.complete.obs", method = "spearman")
Calculating method is person and spearman, you can select what you want.
5. Visualization (four ways)
#++++++++++++++++++++++++++++ Plot 1 ++++++++++++++++++++++++++++++++++++++#
corrplot(Correlation)
#++++++++++++++++++++++++++++ Plot 2 ++++++++++++++++++++++++++++++++++++++#
corrplot(Correlation, method = "square", type = "upper",tl.col = "black", tl.cex = 0.7,col = colorRampPalette(c("blue", "red"))(200))
#++++++++++++++++++++++++++++ Plot 3 ++++++++++++++++++++++++++++++++++++++#
corrplot.mixed(Correlation, upper = "square", lower = "number", addgrid.col = "black", tl.col = "black", tl.cex = 0.55)
#++++++++++++++++++++++++++++ Plot 4 ++++++++++++++++++++++++++++++++++++++#
chart.Correlation(Correlation)
6. Output visualized graph
#+++++++++++++++++++++++++++++ Set working directory +++++++++++++++++++++++++#
getwd()
setwd("F:/SRA/Output_Figure/Corplot")
getwd()
Here, you can check where is your working directory, and set your path.
#+++++++++++++++++++++++++++++ Get output figure ++++++++++++++++++++++++++++++#
tiff(file="corplot_canine_fat_percent.tiff", width = 10, height = 6, units = "in", res = 600)
corrplot.mixed(Correlation, upper = "square", lower = "number", addgrid.col = "black", tl.col = "black", tl.cex = 0.55)
dev.off()
'R > R_Usage [Eng.]' 카테고리의 다른 글
Tax4Fun2 Analysis Tutorial in Rstudio [16S Functional Prediction] (0) | 2022.11.28 |
---|---|
Correlation analysis with R "Hmisc" Package [spearman, pearson] (0) | 2022.11.15 |
Heatmap visualization in Rstudio _ high resoultion figure (0) | 2022.11.08 |
ANOSIM, Statistical analysis with Rstudio (0) | 2022.11.07 |
Rstudio_ working directory default setting (0) | 2022.11.07 |