0

I want to create a plot by breaking the x axis at 3.5, and 9.5 .I found the following code which i have updated according to my data points

x <- c(0.1,0.6,1.5,2.8,10.2,11.8,13.9,14.9,12.5,14.5)
y <- c(1.1,1.8,2.1,5.6,11.2,13.8,10.2,11.1,4.5,9.5)
par(bty="n") # deleting the box
p=gap.plot(x,y, gap=c(3.5,9.5), gap.axis="x", pch=16,
         col="blue", ylim=range(c(y)),
         xtics=c(0:3,10:15), xticlab=c(0:3,10:15))

abline(v=seq(1.99,2.09,.001), col="white")
axis.break(1,2,style="slash")

I am not understanding the last two lines of the code when I used the last line of the code it gives the break after 1 and before 2 so I modified the code as

axis.break(axis = 1, breakpos=3.5 ,style="slash") 

I have no idea how to use the abline to hide the vertical line which i get as seen in the below picture

enter image description here

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
Aishwarya
  • 1
  • 2
  • (1) What does the [tag:java] tag have to do with the question? (2) This is not base R, please include all non-base R packages that are needed to try to reproduce your code. ([tag:plotrix]?) (3) From a vis standpoint, I feel the vertical lines are necessary to prevent the bias you will get without them. That is, without some visual break in the horizontal space, it is easy to miss the fact that the x-axis is not contiguous. (I would go so far as to call the vertical lines "strictly essential".) – r2evans Jan 25 '21 at 13:58

1 Answers1

1

The abline function just plots multiple vertical lines to hide the vertical gap lines:

gap.plot(x,y, gap=c(3.5,9.5), gap.axis="x", pch=16,
         col="blue", ylim=range(c(y)),
         xtics=c(0:3,10:15), xticlab=c(0:3,10:15))
# You do not need `p=` since the function does not return anything
abline(v=c(3.5, 3.7), col="white", lwd=4)
# This hides the gap lines with two wide vertical bars
axis.break(axis = 1, breakpos=3.55 ,style="slash")
# Plot the break markers

You may have to fiddle values in abline to get it to cover the lines.

Gap Plot

If you want to make the gap visible but without the double black lines, you could add the following to plot a dark gray, dashed line in the gap:

abline(v=3.6, col="darkgray", lty=3)
dcarlson
  • 10,936
  • 2
  • 15
  • 18