最近在做mantel test分析的时候,代码总是报错,错误为Error in as.data.frame.default(spec):
cannot coerce class ‘"function"’ to a data.frame,但是之前是可以运行的,数据换了很多格式还是不行,所以请各位大佬指点,到底是啥原因,多谢大佬!
代码如下:set.seed(123) # 随机种子
library(corrplot)#加载相关热图包
library(vegan)#加载vegan包
ZZPhylum <-read.csv
ZZvsrechem <-read.csv
library(vegan)
library(ggcor)
library(ggplot2)#一定要加载
mantel <- mantel_test(ZZPhylum, ZZvsrechem,
spec.select = list(Proteobacteria = 1,
Actinobacteriota = 2,
Chloroflexi = 3,
Firmicutes = 4,
Acidobacteriota = 5,
Bacteroidota = 6,
Myxococcota = 7,
Gemmatimonadota = 8,
Cyanobacteria = 9,
Bdellovibrionota = 10
#依次定义十种物种作为Mantel的分析对象
)) %>%
mutate(rd = cut(r, breaks = c(-Inf, 0.2, 0.4, Inf),
labels = c("< 0.2", "0.2 - 0.4", ">= 0.4")),#定义Mantel的R值范围标签,便于出图
pd = cut(p.value, breaks = c(-Inf, 0.01, 0.05, Inf),
labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))#定义Mantel检验的p值范围标签,便于出图
dev.new(
title = "mantel test",
width = 16,
height = 8,
noRStudioGD = TRUE)
quickcor(ZZvsrechem, type = "upper") +#绘制理化数据热图
geom_square() +#定义成方块状
scale_fill_gradient2(low = 'blue',mid = 'white',high = 'red')+#填充颜色
anno_link(aes(colour = pd, size = rd), data = mantel) +#定义连线
scale_color_manual(values = c("red","lightgrey"))+#连线颜色
scale_size_manual(values = c(0.5, 1, 2))+
guides(size = guide_legend(title = "Mantel's r",#定义图例
order = 2),
colour = guide_legend(title = "Mantel's p",
order = 3),
fill = guide_colorbar(title = "Pearson's r", order = 4))
Error in as.data.frame.default(spec):
cannot coerce class ‘"function"’ to a data.frame


雷达卡


京公网安备 11010802022788号







