R语言绘制sorensen相异性指数图
时间: 2023-05-27 11:04:41 浏览: 277
消费电子中的AMETEK Sorensen针对激光二极管测试的解决方案
以下是绘制Sorensen相异性指数图的R语言代码示例:
# 导入所需的包
library(vegan)
# 创建数据框
dat <- data.frame(matrix(nrow=5, ncol=4))
colnames(dat) <- c("Site 1", "Site 2", "Site 3", "Site 4")
rownames(dat) <- c("Species 1", "Species 2", "Species 3", "Species 4", "Species 5")
dat[,1] <- c(1, 0, 1, 0, 1)
dat[,2] <- c(0, 1, 1, 0, 0)
dat[,3] <- c(1, 0, 1, 1, 1)
dat[,4] <- c(0, 0, 1, 1, 1)
# 计算Sorensen相异性指数
sor <- simba(dat, index="sor")
# 绘制Sorensen相异性指数矩阵(heatmap)
heatmap(sor, Rowv = NA, Colv = NA, scale="none", col = colorRampPalette(c("#ffffff", "#2a57ab"))(20), margins=c(5,5))
# 添加行和列标签
text(seq(0.5, 4.5, by = 1), seq(0.5, 5.5, by = 1), colnames(dat), cex = 1.5)
text(seq(-0.5, -4.5, by = -1), seq(0.5, 5.5, by = 1), rev(rownames(dat)), cex = 1.5, srt = 90, adj = c(0,0.5))
# 添加颜色刻度条
image.plot(legend.only = TRUE, col = colorRampPalette(c("#ffffff", "#2a57ab"))(20), xlim = c(0, 1), ylim = c(0, 1), zlim = c(0, 1),axes = FALSE, legend.shrink = 1, legend.mar = 10, legend.width = 1, legend.lab = c("0", "1"), legend.args = list(text = list(cex = 1.5)), breaks = seq(0, 1, length.out = 21))
阅读全文