1

I have used Thinkcell, and one of its cool features is that it breaks very long y-axis to fit the graph. I am not sure whether we can do this with ggplot2. I am a beginner in ggplot2. So, I'd appreciate any thoughts.

For example:

Series <- c(1:6)
Values <- c(899, 543, 787, 35323, 121, 234)
df_val_break <- data.frame(Series, Values)

ggplot(data=df_val_break, aes(x=Series, y=Values)) +
  geom_bar(stat="identity")

This creates a graph like this:

enter image description here

However, I want a graph that looks something like this:

enter image description here

However, it seems that broken axis is not supported in ggplot2 because it's misleading (Source: Using ggplot2, can I insert a break in the axis?). This thread suggests a couple of things--faceting and tables.

While I like tables, but I don't like faceting because my categorical variable "Series" are closely related. Moreover, I'd prefer Excel for drawing tables--it's fast.

I have two questions:

Question 1: One of the options I liked is at https://stats.stackexchange.com/questions/1764/what-are-alternatives-to-broken-axes. The graph is at enter image description here.

I am unable to replicate similar graph because of the scaling issue.

Question 2: This is a minor question just in case there were new packages introduced that might help us to do this. (The linked SO thread above is older than 5 years. ) Are there any other options on the table?


Update: I don't think my question is duplicate for two reasons: a) I have already gone through the indicated thread, and have referenced here explaining that I am looking for a solution that looks like the third graph in my post. Specifically, I am looking to plot both the graphs--one with shorter scales and the other with 1/20 scale in one graph. I am unable to do this using ggplot2 because of scale issue. Either both the sub-graphs get scaled to 1/nth or one of them get scaled to normal range. I believe this version is much relatable for non-technical audience who don't understand log and Inverse transformation.

enter image description here

jay.sf
  • 60,139
  • 8
  • 53
  • 110
watchtower
  • 4,140
  • 14
  • 50
  • 92
  • 2
    Hadley has been clear that he does not allow discontinuous or double y-axes in ggplot because he thinks they're misleading. In this case, a log transformation with `+ scale_y_log10()` makes the graph more palatable. – alistaire Sep 05 '16 at 01:10
  • @alistaire Thanks for your help. I agree, but I believe my audience might not get log scales. That's why I was looking for a solution that goes well with non-technical or non-statistically savvy audience. I hope you understand. – watchtower Sep 05 '16 at 01:12
  • I highly recommend `+ annotation_logticks()` for helping convey the values of a a log scale. you can even adjust `base = numeric(x)`. plus discontinuous scales are the devils work -team_tidyverse – Nate Sep 05 '16 at 01:36
  • ok, I reopened the question – Jaap Sep 05 '16 at 17:34
  • @Procrastinatus.. Thanks so much. I took a stab at this one. I'd appreciate any thoughts. – watchtower Sep 05 '16 at 18:36
  • 1
    Don't do this with bar charts; it's just misleading. – Jack Aidley Sep 05 '16 at 18:39

1 Answers1

0

I took a stab at this one. I'm a beginner so I am not sure whether this can be improved further in terms of placement of text. I struggled with fitting both high growth rate series and low growth rate series in one graph because of different scales. So, I used facetting.

Here's the code:

 ggplot(data = df_val_break,aes(x=Series,y=Values)) +
       geom_bar(stat = "identity") + 
       facet_wrap(~Modified) + 
       geom_text(data = df_val_break[df_val_break$Modified=="HIGH_GROWTH",], aes(label = "x20 growth rate"),hjust=0.5, vjust=0)
     ggsave("post.png")

Here's the output: enter image description here There are quite a few issues that I see:

a) High_growth rate graph has Series 2 and Series 6 on the x-axis, although we don't need them. I don't know how to turn them off.

b) geom_text overlaps with the bar. This looks a little annoying.

c) I'd believe that the graph is a little misleading, especially for HIGH_GROWTH section because the y-axis isn't scaled with LOW_GROWTH I was originally thinking of showing two different y-axis--one scaled by 1/20 and the other unscaled.

watchtower
  • 4,140
  • 14
  • 50
  • 92