About R question: how to analyse the correlation between two datasets (corr.test and corrplot)
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:enter image description here

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

(1) my_data = https://drive.google.com/file/d/1ieHhMf1SgWZL75RBDc6Gza4rHjkKAIux/view?usp=sharing

(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 :)

my_data <- read.csv(file.choose())
bacteria <- read.csv(file.choose())
row.names(bacteria) <- LETTERS[1:10]
row.names(my_data) <- LETTERS[1:10]

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) %>%
spread(var, value) %>%
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

Login before adding your answer.

Traffic: 2520 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6