简体   繁体   English

R:在CCA图中添加双图箭头

[英]R: adding biplot arrows to CCA plot

Starting with the following code: 从以下代码开始:

library(vegan)
data(dune)
data(dune.env)
Ordination.model1 <- cca(dune ~ Management,dune.env)
plot1 <- plot(Ordination.model1, choices=c(1,2), scaling=1)

I get a plot with sites, species, centroids, and biplot arrows. 我得到了一个包含地点,物种,质心和双线图箭头的图。 I want to build up a plot with just the sites depicted by points, and the arrows with customized labels. 我只想用点所描绘的地点以及带有自定义标签的箭头来构建地块。 So far, I have: 到目前为止,我有:

colvec <- c("red", "green", "blue")
plot(Ordination.model1, type="n", scaling=1)
with(dune.env, points(Ordination.model1, display ="sites", col=colvec[Use], scaling=1, pch =16, bg = colvec[Use]))

I am stuck as far as how to put the arrows in. Thanks in advance! 我对如何插入箭头感到困惑。在此先感谢!

You can add arrows using text. 您可以使用文本添加箭头。 I was not able to use your code as I kept getting errors, however here is a basic example that does what you want. 由于不断出现错误,因此我无法使用您的代码,但是这是一个可以满足您需求的基本示例。 I took it from R Help: CCA Plot Once you add text the arrows should show. 我从R帮助:CCA图中获取了它。添加文本后,箭头应显示出来。

require(vegan) 
data(varespec) 
data(varechem)

vare.cca <- cca(varespec ~ ., data = varechem) 
plot(vare.cca, display = c("sites","species"), scaling = 3)
text(vare.cca, scaling = 3, display = "bp") 

Here is an example with the labels argument: 这是带有labels参数的示例:

## S3 method for class 'cca':
text((x, display = "sites", labels, choices = c(1, 2),
scaling = "species", arrow.mul, head.arrow = 0.05, select, const,
axis.bp = TRUE, correlation = FALSE, hill = FALSE, ...))

labels: Optional text to be used instead of row names: Plot or Extract Results of Constrained Correspondence Analysis or Redundancy Analysis 标签:代替行名使用的可选文本: 约束对应分析或冗余分析的绘图或提取结果

I was able to rename the arrows: below is the full code. 我能够重命名箭头:下面是完整的代码。

library(vegan)
data(dune)
data(dune.env)
Ordination.model1 <- cca(dune ~ Management,dune.env)
summary(Ordination.model1)  # Lets you see the current biplot labels in the output.
colvec <- c("red", "green", "blue", "orange")   
plot(Ordination.model1, type="n", scaling=1)
with(dune.env, points(Ordination.model1, display ="sites", col=colvec[Management],scaling=1, pch =16, bg = colvec[Management]))
labl <- c("HF", "NM", "SF")   # new labels.  Need to be in the same order as the old biplot labels.
text(Ordination.model1, display="bp", scaling=1, labels=labl)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM