How to make gap between x / y axis and protruding tongs in ggplots
3 answers
One option is to remove inline axes and then use geom_segment
to add axes with a space. To make it easier to get the broken centerlines in the right place, we also use scale_y_continuous
to pinpoint where we want the axial breaks and limits. The code also shows how to increase the size of the labels.
ggplot(data=mpg, aes(class, hwy)) +
geom_segment(y=10, yend=50, x=0.4, xend=0.4, lwd=0.5, colour="grey30", lineend="square") +
geom_segment(y=5, yend=5, x=1, xend=length(unique(mpg$class)),
lwd=0.5, colour="grey30", lineend="square") +
geom_boxplot() +
scale_y_continuous(breaks=seq(10,50,10), limits=c(5,50), expand=c(0,0)) +
theme_classic(base_size=12) +
theme(axis.line = element_blank(),
axis.ticks.length = unit(7,"pt"))
+5
source to share