2

I'm the R novice and I need some help. I'm trying to add second plot to one created in gap.barplot(), but failing. 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 = "")    

Image of the plot

But after I'm trying to do the same with the second plot, smth goes wrong:

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:

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)    

What am I doing wrong?

Thanks in advance!

1 Answers1

1

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.

enter image description here

Community
  • 1
  • 1
Christoph
  • 6,841
  • 4
  • 37
  • 89
  • Thanks, Cristoph! I've found this answer myself, but that's not the thing i wanted: It doesn't really make gap in the axis, just makes a gap-looking patch on. (( – Aleks Zhang Nov 25 '16 at 16:20
  • @Aleks Zhang I don't understand. See my example above. What do you expect then? – Christoph Nov 28 '16 at 08:15