About R question: how to analyse the correlation between two datasets (corr.test and corrplot)
0
0
Entering edit mode
5 weeks ago
Angelrica • 0

Hi. I am Newbie in R. I am facing the problem of corr.test analysis. Actually, I would like to clarify the correlation between two different vectors ( Bacteria types versus environment factors).

Then, I would like to plot a graph like this:

There are two dataset for my analysis, here's the link:

(2) bacteria = enter link description here

First, I follow the code that reply by former professional in R studio community and try to run the code as below. However, at the end, it appears this kind of error message as below: Can't subset columns that don't exist. x Column rowname doesn't exist. Run rlang::last_error() to see where the error occurred.

So, I think I have made some mistake in this corr.test and graph plotting, can anyone help me to solve this problem or discuss with me ? Thank you very much :)

library(tidyverse)
library(corrplot)
library(corrr)
row.names(bacteria) <- LETTERS[1:10]
row.names(my_data) <- LETTERS[1:10]

library(RColorBrewer)
df <- bind_cols(bacteria[, -1],my_data[, -1])
res1 <- cor.mtest(df, conf.level = 0.95)
res2 <- res1$p %>% as.data.frame() %>% res2 <- res1$p %>%
rownames<-(colnames(df)) %>%
colnames<-(colnames(df)) %>%
rownames_to_column("rowname") %>%
gather("var", "p", -rowname)

corrr::correlate(bind_cols(my_data[, -1], bacteria[, -1])) %>%
gather("var", "value", -rowname) %>%
left_join(res2) %>%
mutate(value = ifelse(p < 0.05, NA_integer_, value)) %>%
select(-p) %>%
filter(rowname %in% colnames(my_data)) %>%
select(one_of(c("rowname", colnames(bacteria)[-1]))) %>%
as.data.frame() %>%
column_to_rownames("rowname") %>%
as.matrix() %>%
corrplot::corrplot(is.corr = FALSE, na.label.col = "white", col = brewer.pal (n=10, name= "PuOr"), tl.col = "black", tl.srt = 45)

corrplot correlation matrix R • 139 views
0
Entering edit mode