【发布时间】:2020-03-03 21:02:38
【问题描述】:
我在素食主义者中使用 capscale 生成了一个存在-不存在社区组成数据的 capscale 模型。我可以使用以下代码使用基础 R
生成绘图(SOR.capscale <- capscale(SOR ~ df.meta.clin.week.snake$copy.num + df.meta.clin.week.snake$exp.time, df.otus.clin.week.snake.nonzero)) #specify model
plot(SOR.capscale, main = "Capscale Analysis", xlab = "CAP1", ylab = "CAP2")
points(SOR.capscale, col = expgroup)
ordihull(SOR.capscale, expgroup, col = c("black", "red"), label = FALSE, display = "sites")
这会生成以下可视化效果
我已使用以下代码从 capscale 模型中提取 CAP 值以将它们绘制在 ggplot 中
x <- as.data.frame(scores(SOR.capscale, display = "sites"))
df.pred.clin.week.snake$CAP1 <- x$CAP1
df.pred.clin.week.snake$CAP2 <- x$CAP2
我已经使用这些数据在 ggplot 中使用列出的代码生成了一个绘图
ggplot(df.pred.clin.week.snake, aes(x= CAP1, y= CAP2, color = expgroup)) +
stat_ellipse(aes(fill = expgroup), geom = "polygon", alpha = 0.2) +
geom_point() +
theme_classic() +
coord_cartesian(xlim=c(-20, 20), ylim=c(-6.5, 15)) +
geom_hline(yintercept = 0, linetype="dotted") +
geom_vline(xintercept = 0, linetype="dotted") +
labs(color = "Experimental Treatment", fill = "Experimental Treatment") +
ggtitle("Capscale Analysis") +
theme(plot.title = element_text(hjust = 0.5))
ylab("CAP2") +
xlab("CAP1")
我的问题是如何从 capscale 分析模型中提取矢量信息,以便我能够使用 ggplot 绘制它们?非常感谢!
【问题讨论】:
标签: r dataframe ggplot2 extract vegan