如何在plotrix包中添加plot到gap.barplot?

时间:2016-10-23 18:34:05

标签: r plot plotrix

我是R新手,我需要一些帮助。 我正在尝试将第二个绘图添加到gap.barplot()中创建的一个,但是失败了。 我有两个向量:

UITabBarController

绘制第一个是好的:

y <- as.numeric(c(92, 8, 7,6,5))
z <- as.numeric(c(7.5, 5.9, 5.2, 4.5, 2.3))    

Image of the plot

但是在我试图对第二个情节做同样的事情之后,smth出了问题:

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

我看到奇怪的倒置情节和错误信息:

Inverted plot

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)    

我做错了什么?

提前致谢!

1 个答案:

答案 0 :(得分:1)

我找到了thisthis相关帖子,但遇到了同样的麻烦。这是基于第二篇文章的解决方案:

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

我希望有所帮助。

enter image description here

相关问题