[英]How to add plot to gap.barplot in plotrix package?
I'm the R novice and I need some help.我是 R 新手,我需要一些帮助。 I'm trying to add second plot to one created in gap.barplot(), but failing.我正在尝试将第二个图添加到在 gap.barplot() 中创建的图,但失败了。 I have two vectors:我有两个向量:
y <- as.numeric(c(92, 8, 7,6,5))
z <- as.numeric(c(7.5, 5.9, 5.2, 4.5, 2.3))
Plotting the first one is ok:绘制第一个没问题:
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 = "")
But after I'm trying to do the same with the second plot, smth goes wrong:但是在我试图对第二个情节做同样的事情之后,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)
I see strange inverted plot and the error message:我看到奇怪的倒置图和错误消息:
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)
What am I doing wrong?我究竟做错了什么?
Thanks in advance!提前致谢!
I found this and this related posts but ran into the same trouble.我找到了这个和这个相关的帖子,但遇到了同样的麻烦。 Here is a solution based on the second post:这是基于第二篇文章的解决方案:
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")
I hope that helps.我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.