get "//" in xaxis

Hello,

My date looks like this
"data <- data.frame( x = c(1, 2, 3, 4, 5, 100), y = c(10, 20, 30, 40, 50,50))

Create plot

p <- ggplot(data, aes(x = x, y = y)) +
geom_point() +
scale_x_continuous(breaks = c(0 ,1, 2, 3, 4, 5, 100), limits = c(0, 100)) +
scale_y_continuous(limits = c(0,50),breaks = seq(from=0, to =50, by=10))
p"

there huge gap between the xticks 5 and 100, i want to remove the gap and see the ticks close, and break the ticks with "//"

this is how i want to see my xticks "0,1,2,3,4,5,//,100"

can someone help me to do this ?

Hi @sai_matcha, welcome back to the forum!

In general, no, ggplot2 does not support broken axes, as they can lead to misleading/incorrect visualizations. When you see that in a published paper, it's often done using Adobe Illustrator or a similar image editing program.

For a couple of examples of what you can achieve using ggplot and some other R packages, please see this StackOverflow thread:

One of the mentioned examples, ggbreak, handles this using ggplot2:
https://cran.r-project.org/web/packages/ggbreak/vignettes/ggbreak.html

Best,
Randy

1 Like

Thanks alot @randyzwitch

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.