【问题标题】:How to add plot to gap.barplot in plotrix package?如何将绘图添加到 plotrix 包中的 gap.barplot?
【发布时间】:2016-11-28 16:15:12
【问题描述】:

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

Image of the plot

但是在我尝试对第二个情节做同样的事情之后,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)    

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

Inverted plot

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)    

我做错了什么?

提前致谢!

【问题讨论】:

    标签: r plot plotrix


    【解决方案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")
    

    希望对你有帮助。

    【讨论】:

    • 谢谢,克里斯托夫!我自己找到了这个答案,但这不是我想要的:它并没有真正在轴上产生间隙,只是在上面做了一个看起来有间隙的补丁。 (((
    • @Aleks Zhang 我不明白。请参阅我上面的示例。那你期待什么?
    猜你喜欢
    • 2020-05-17
    • 2021-02-13
    • 1970-01-01
    • 2016-08-28
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多