简体   繁体   中英

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.

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

在此输入图像描述

It looks like that dotted line is created by the plot function from looking at lines 66 and 67 of the source code :

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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