Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

plot

r

vegan

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.

like image 699
kylezenh0 Avatar asked Nov 27 '25 04:11

kylezenh0


1 Answers

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

enter image description here

like image 114
Gavin Simpson Avatar answered Nov 28 '25 18:11

Gavin Simpson