在 R 中使用 plot() 时如何摆脱网格? [英] How do I get rid of grids when using plot() in R?

查看:82
本文介绍了在 R 中使用 plot() 时如何摆脱网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用 R 通过 Vegan 包执行 DCA(去趋势对应分析),每次我绘制结果时,我都会在绘图中间得到一个网格.

我想摆脱它.

这是我的代码:

dca <-decorana(dados)情节(DCA,类型=n",安=假,原点=真)文本(DCA,显示=站点")点(dca,显示=物种",pch=21,col=红色",bg=红色",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)

结果如下:

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.

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

Do you see that grid line from x=0 and 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.

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. 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

这篇关于在 R 中使用 plot() 时如何摆脱网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆