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))
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:
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.