簡體   English   中英

在R中使用plot()時如何擺脫網格?

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

所以我使用R來通過素食包進行DCA(去趨勢對應分析),每當我繪制結果時,我會在情節中間得到一個網格。

我想擺脫它。

這是我的代碼:

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)

這是結果: DCA情節

你看到x = 0和y = 0的網格線? 那就是問題所在。

正如現有的各種文檔和教程中經常提到的,如果你不喜歡plot()生成的默認圖,你可以自由地使用R提供的低級繪圖函數或我們提供的中間函數來構建你自己的圖。在素食主義者

這里的主要復雜因素是,出於這樣或那樣的原因,我們不能在plot方法中用type = "none"繪制原點線。 但即便如此,也可以通過自己繪制得分來解決。

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

這是默認plot.decorana和上面繪制的內容的並排比較

在此輸入圖像描述

看起來這個虛線是由繪圖函數通過查看源代碼的第66和67行創建的:

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

擺脫它的唯一方法是復制功能代碼並刪除這兩行。

繪制兩條白線來遮蓋它們,然后在頂部繪制你的點。

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

然后繪制一個框以移除邊框在邊框中創建的間隙

box()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM