Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

r - Breaking the x axis

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

question from:https://stackoverflow.com/questions/65886030/breaking-the-x-axis

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...