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:
(1) my_data = https://drive.google.com/file/d/1ieHhMf1SgWZL75RBDc6Gza4rHjkKAIux/view?usp=sharing
(2) bacteria = https://drive.google.com/file/d/1T_o5yntbSAdNdo7be5Ki1dpmhsQBD5Ic/view?usp=sharing
First, please forgive me that I copy and paste the code instead of using "reprex", so sorry as R always appear such kind of message: This reprex appears to crash R....
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)
my_data <- read.csv(file.choose())
my_data
bacteria <- read.csv(file.choose())
bacteria
row.names(bacteria) <- LETTERS[1:10]
bacteria
has_rownames(bacteria)
row.names(my_data) <- LETTERS[1:10]
my_data
has_rownames(my_data)
library(RColorBrewer)
df <- bind_cols(bacteria[, -1],my_data[, -1])
res1 <- cor.mtest(df, conf.level = 0.95)
res2 <- res1$p %>%
as.data.frame() %>%
rownames<-
(colnames(df)) %>%
colnames<-
(colnames(df)) %>%
rownames_to_column("rowname") %>%
gather("var", "p", -rowname)
head(res2)
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)
As result, 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.