[英]How to break axis in a barplot (maybe using plotrix gap.barplot)?
我發現了很多 SO 問題和答案,解決了軸上的斷裂和差距。 但是由於沒有示例代碼、沒有圖片或復雜的代碼,它們中的大多數都是低質量的(在 SO 的意思中)。 這就是我問的原因。
我嘗試使用library(plotrix)
。 如果有沒有它和/或另一個庫的解決方案,對我來說也可以。
這是一個正常的 R-barplot。
barplot(c(10,20,500))
為了打破軸並增加間隙,我嘗試了這個。
gap.barplot(c(10,20,500),gap=c(50,400), col=FALSE)
結果並不漂亮。
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")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.