【问题标题】:How to plot vectors from capscale analysis in ggplot2?如何在ggplot2中从capscale分析中绘制向量?
【发布时间】: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


    【解决方案1】:

    在 capscale 中,信息可以告诉您箭头来自哪里,通常是 SOR.capscale$CCA$biplot - 无论这些数字是什么,您都可以将它们插入:

    plot + geom_segment(aes(x = 0.0, y =0.0,xend = 10.9 , yend = -0.01), arrow =arrow())+ geom_segment(aes(x = 0.0, y =0.0, xend = 0.01, yend = 10.1), arrow =arrow())

    或者你的实际数字是什么。

    【讨论】:

      猜你喜欢
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 1970-01-01
      • 2016-10-05
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多