簡體   English   中英

如何在條形圖中打破軸(可能使用 plotrix gap.barplot)?

[英]How to break axis in a barplot (maybe using plotrix gap.barplot)?

我發現了很多 SO 問題和答案,解決了軸上的斷裂和差距。 但是由於沒有示例代碼、沒有圖片或復雜的代碼,它們中的大多數都是低質量的(在 SO 的意思中)。 這就是我問的原因。

我嘗試使用library(plotrix) 如果有沒有它和/或另一個庫的解決方案,對我來說也可以。

這是一個正常的 R-barplot。

barplot(c(10,20,500))

帶有標准 R 的條形圖

為了打破軸並增加間隙,我嘗試了這個。

gap.barplot(c(10,20,500),gap=c(50,400), col=FALSE)

使用 plotrix 庫的條形圖

結果並不漂亮

  • 酒吧之間沒有空間。 space從參數barplot()不被接受gap.barplot()
  • 條具有不同的寬度。
  • 抽動的位置不在橫杠中間。

我可以用plotrix控制這些參數嗎? 我在文檔中沒有看到有關它的內容。 我的問題還有其他圖書館或解決方案嗎?

由於很多個人問題,有很多不同的答案。 對於您的問題,您可以嘗試以下操作。 但總有更好的解決方案。 而且 IMO 總是更好地顯示您的完整數據而不是裁剪它。

# Your data with names
library(plotrix)
d <- c(10,20,500)
names(d) <- letters[1:3]
# Specify a cutoff where the y.axis should be splitted.
co <- 200
# Now cut off this area in your data.
d[d > co] <- d[d > co] - co
# Create new axis label using the pretty() function
newy <- pretty(d)
newy[ newy > co] <- newy[ newy > co] + co
# remove values in your cutoff. 
gr <- which(newy != co)
newy <- newy[ gr ]
# plot the data
barplot(d, axes=F)
# add the axis
axis(2, at = pretty(d)[gr], labels = newy)
axis.break(2, co, style = "gap") 

在此處輸入圖片說明 作為替代方案,您可以嘗試使用log="y"記錄您的軸。

暫無
暫無

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

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