1

I want to make a plot with not equally spaced axis. Here is my data.

group <- c("group1","group2","group3","group4","group5","group6")
value <- c(520,550,13,15,30,20)
df <- cbind.data.frame(group,value)

I want to make a plot like this. idealplot

I tried to make it using ggplot, like this.

ggplot(df,aes(x=factor(group),y=value))+geom_bar(stat="identity")

This code makes a plot with equally spaced axis which I do not want. This plot is unable to compare group 3,4,5 and 6. If you know how to make the ideal plot, please let me know. undesiredplot

tayu
  • 33
  • 1
  • 1
  • 5

1 Answers1

1

I don't think I've ever seen a discontinuous axis in ggplot2.

With points instead of bars, you can fake a discontinuous axis by using facets:

ggplot(df,aes(x=factor(group),y=value)) +
    facet_grid(value < 100 ~., scales='free_y') +
    geom_point(stat="identity") + 
    theme(strip.text = element_blank())

discontinuous Y emulated with facets

Other alternatives to visualizing data with large differences in values is to log-transform or sqrt-transform the Y axis, which effectively stretches out small values and compresses large values.

ggplot(df,aes(x=factor(group),y=value)) +
    geom_bar(stat="identity") + 
    scale_y_log10() +
    annotation_logticks(base=10, sides='lr')

specify

cymon
  • 413
  • 2
  • 9
  • 1
    Thank you cymon. Your ideas are great. And your question gave me a hint and then I searched "break axis". I could find the code below and this is close(not exact) to what I want. library(plotrix); gap.barplot(df$value,gap=c(50,500)) – tayu Mar 27 '20 at 22:54