简体   繁体   English

在R中使用plot()时如何摆脱网格?

[英]How do I get rid of grids when using plot() in R?

So I'm using R to perform a DCA (detrended correspondence analysis) through Vegan package and everytime I plot my results I get a grid in the middle of the plot. 所以我使用R来通过素食包进行DCA(去趋势对应分析),每当我绘制结果时,我会在情节中间得到一个网格。

I want to get rid of it. 我想摆脱它。

Here is my code: 这是我的代码:

dca <- decorana(dados)

plot(dca, type = "n", ann = FALSE, origin = TRUE)
        text(dca, display = "sites")
        points(dca, display = "species", pch = 21, col="red", bg = "red", cex=0.5)
        mtext(side = 3, text = "Análise de Correspondência Retificada (DCA)", font=2, 
              line = 2.5, cex=1.8, font.lab=6, cex.lab=2, cex.axis=1.5)
        mtext(side = 1, text = "Eixo I", font=2, line = 2.5, cex=1.5, 
              font.lab=6, cex.lab=2, cex.axis=2)
        mtext(side = 2, text = "Eixo II", font=2, line = 2.5, cex=1.5, 
              font.lab=6, cex.lab=2, cex.axis=2)

And here is the result: DCA plot 这是结果: DCA情节

Do you see that grid line from x=0 and y=0? 你看到x = 0和y = 0的网格线? That's the problem. 那就是问题所在。

As is mentioned frequently in the various documentation and tutorials in existence, if you don't like the default plots produced by plot() you are free to build your own from either the low level plotting functions supplied by R or the intermediate functions we provide in vegan . 正如现有的各种文档和教程中经常提到的,如果你不喜欢plot()生成的默认图,你可以自由地使用R提供的低级绘图函数或我们提供的中间函数来构建你自己的图。在素食主义者

The main complication here is that, for one reason or another, we can't not plot the origin lines with type = "none" in the plot method. 这里的主要复杂因素是,出于这样或那样的原因,我们不能在plot方法中用type = "none"绘制原点线。 But even that is solvable by plotting the scores yourself. 但即便如此,也可以通过自己绘制得分来解决。

library("vegan")
data(dune)
dca <- decorana(dune)
spp <- scores(dca, 1:2, display = "species")
sit <- scores(dca, 1:2, display = "sites")
xlim <- range(spp[,1], sit[,1])
ylim <- range(spp[,2], sit[,2])
plot(spp, type = "n", xlim = xlim, ylim = ylim, asp = 1, ann = FALSE)
text(sit[,1], sit[,2], labels = rownames(sit))
points(spp, pch = 21, col = "red", bg = "red", cex = 0.5)
title(xlab = "DCA 1", ylab = "DCA 2")

Here's a side-by-side comparison of the default plot.decorana and what the above draws 这是默认plot.decorana和上面绘制的内容的并排比较

在此输入图像描述

It looks like that dotted line is created by the plot function from looking at lines 66 and 67 of the source code : 看起来这个虚线是由绘图函数通过查看源代码的第66和67行创建的:

abline(h = 0, lty = 3)
abline(v = 0, lty = 3)

The only way to get rid of it is if you copy the function code and remove those two lines. 摆脱它的唯一方法是复制功能代码并删除这两行。

Draw two white lines to cover them up, then draw your points on top. 绘制两条白线来遮盖它们,然后在顶部绘制你的点。

abline(h=0, col="white")
abline(v=0, col="white")

Then draw a box to remove the gaps created in the border by the ablines 然后绘制一个框以移除边框在边框中创建的间隙

box()

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

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