0

I need to put a break in y-axis between 25,000 and 200,000. Here is the code and I can't figure out why it doesn't give me the y-axis I need. I need the first portion to go from 0 to 25,000 in steps of 5,000 and the second part to go from 200,000 to 2 million in steps of 500K.

x <- c(1000000, 5000000, 10000000, 15000000, 20000000, 25000000, 
       30000000, 35000000, 40000000, 45000000, 50000000, 55000000,
       60000000, 65000000, 70000000, 75000000, 80000000, 85000000,
       90000000, 95000000, 100000000)

y <- c(3305.8, 4175.4, 4175.4, 4201.7, 4201.7, 23529.4, 23529.4, 23529.4, 23529.4,
       23529.4, 23529.4, 23529.4, 23529.4, 23529.4, 23529.4, 23529.4, 23529.4,
       285714.3, 2000000.0, 2000000.0, 2000000)

library(plotrix)
gap.plot(x, y, gap = c(25000, 200000), gap.axis = "y", ylim = c(0, 2000000),
             ytics = c(seq(0, 25000, by = 5000), seq(200000, 2000000, by = 500000)))
        axis.break(axis = 2, breakpos = 25000, style = "slash")
Miha
  • 2,559
  • 2
  • 19
  • 34
Angus
  • 355
  • 2
  • 12
  • When your max is 2 million, the implicit scaling will not allow 25,000 to be very high up. You should explain your expectation better. It doesn't appear that axis.break or gap.plot allow for scales that differ at different heights. – IRTFM Mar 22 '18 at 20:19
  • You really shouldn't put different scales on one plot. Data on one plot should be comparable. Either split them up, or use one scale. – Anonymous coward Mar 22 '18 at 20:40

1 Answers1

1

You can create a bit of a work-around for this issue. I'm assuming you want the plot to be more readable. You can reduce the magnitude of the very large values to make them more comparable to the smaller values while keeping the original axis labels. That is,

y2 <- ifelse(y>25000, y/100 + 25000, y)
gap.plot(x,y2,gap=c(25000,25000), gap.axis="y",ylim=c(0,2000000/100 + 25000),
         ytics=c(seq(0,25000,by=5000),seq(27000,45000,by=5000)),
         yticlab=c(seq(0,25000,by=5000),seq(200000,2000000,by=500000)))
axis.break(axis=2,breakpos=25000,style="slash")
smanski
  • 541
  • 2
  • 7