![](/img/trans.png)
[英]How to break axis in a barplot (maybe using plotrix gap.barplot)?
[英]How to add plot to gap.barplot in plotrix package?
我是 R 新手,我需要一些幫助。 我正在嘗試將第二個圖添加到在 gap.barplot() 中創建的圖,但失敗了。 我有兩個向量:
y <- as.numeric(c(92, 8, 7,6,5))
z <- as.numeric(c(7.5, 5.9, 5.2, 4.5, 2.3))
繪制第一個沒問題:
gap.barplot(y,
gap = c(9, 80),
ytics=c(2,4,6,8,90,92),
col=rep("lightsalmon", 5),
xaxt = "n",
ylab = "Frequencies, n",
xlab = "")
但是在我試圖對第二個情節做同樣的事情之后,smth 出錯了:
gap.barplot(z,
gap = c(9, 80),
ytics=c(2,4,6,8,90,92),
col=rep("green", 5),
xaxt = "n",
ylab = "Frequencies, n",
xlab = "",
main = "Colors",
add = T)
我看到奇怪的倒置圖和錯誤消息:
Error in rect(xtics[bigones] - halfwidth, botgap, xtics[bigones] + halfwidth, :
не могу смешивать координаты нулевой длины с ненулевыми (can not mix the coordinates of length zero with non-zero)
In addition: Warning messages:
1: In plot.window(...) : "add" -- не графический параметр (not graphics option)
2: In plot.xy(xy, type, ...) : "add" -- не графический параметр (not graphics option)
3: In title(...) : "add" -- не графический параметр (not graphics option)
4: In axis(1, at = xtics, labels = xaxlab, ...) :
"add" -- не графический параметр (not graphics option)
5: In axis(2, at = c(ytics[littletics], ytics[bigtics] - gapsize), :
"add" -- не графический параметр (not graphics option)
我究竟做錯了什么?
提前致謝!
我找到了這個和這個相關的帖子,但遇到了同樣的麻煩。 這是基於第二篇文章的解決方案:
y <- as.numeric(c(92, 8, 7,6,5))
z <- as.numeric(c(7.5, 5.9, 5.2, 4.5, 2.3))
data=cbind(y,z);
library(plotrix)
barpos<-barplot(data,names.arg=colnames(data),
ylim=c(0,100),beside=TRUE,col=c("darkblue","red"),axes=FALSE)
axis(2,at=c(2,4,6,8,90,92),
labels=c(2,4,6,8,90,92))
box()
axis.break(9,80,style="gap")
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.