1

I want to plot small values with only a few runaway values, and do not want to change the axis scale, but brake it instead.

As there does not seem to be a builtin support for braking an axis in ggplot2, I just changed the axis labels and modified the values accordingly:

library(ggplot2)

df <- data.frame(
  x=seq(1,10),
  y=c(1,5,10,64,3,11,40,640,3,11)
)

df$yn <- ifelse(df$y<=80,df$y,df$y*.1+40)

ggplot(df, aes(x=x,y=yn)) + geom_line() + geom_point() + 
  theme_classic() +
  scale_y_continuous(breaks=seq(10,110,10), labels = c(10, 20, 30, 40, 50, 60, 70, "", 500, 600, 700)) 

plot

the only thing that I want to improve is the visual representation. What I want to achieve is to remove (if possible) the single y axis tick for position 80 (no label displayed), and draw some horizontal lines over the axis to illustrate the broken axis. Here is a faked version how it could look like then:

enter image description here

Is there any way to hide the single tick and draw those lines? I only know of geom_hline, but I haven't manage to draw not across the whole x axis.

[Edit]

Not a duplicate: I found that question about discontinous axis as well. But as the question stated that this isn't possible with ggplot2, I found an answer by myself and solved the problem of having a discontinuous axis by transforming the values and renaming my labels. My problem is about inserting some small lines and hiding a single tick, not about how to realize discontinuos axis.

muffel
  • 7,004
  • 8
  • 57
  • 98
  • You should also remove any lines that cross the break as they are clearly misleading. – Axeman Mar 14 '17 at 14:18
  • @beetroot no, not a duplicate: I found that question and solved the problem of having a discontinuous axis by transforming the values and renaming my labels. My problem is about inserting some small lines and hiding a single tick. – muffel Mar 14 '17 at 14:36
  • @Axeman you're right, that would be great as well (any idea how to do this?) – muffel Mar 14 '17 at 14:36
  • @muffel The answer still is that it's not (easily) possible because it's bad practice and you shouldn't do it. – erc Mar 14 '17 at 15:40
  • @beetroot that's just not what I want to say to my boss... – muffel Mar 14 '17 at 16:18

0 Answers0