0

I'm working with R and ggplot2, and I'd like to plot a barchart with 2 different ranges on the y-axis. Specifically, I want 0 to 65 to have roughly the same size bars as 0 to -0.0650. I'm working with a large data set, but the data takes on a form that looks like this:

State Metric Value
AK    A      -0.0560
AL    A      -0.0600
AR    A      -0.0520
AK    B      46
AL    B      43
AR    B      39

This is the code I've got so far, and all the data is there, but the negative y-axis is so small, the values aren't visible.

p <- ggplot(alcohol, aes(x= State, y= Value, fill= Metric)) + 
  geom_bar(stat="identity") +
  geom_text(aes(label= Value), vjust= -0.3, size= 2) +
  scale_y_continuous(expand= expand_scale()) +
  geom_text(aes(x=1, y= 65, label=" "), vjust=-1)

I've played with scale_y_continuous, scale_y_discrete, limits, breaks, etc. and I can't seem to figure out how to do make the bars negative y-axis more prominent. Any tips?

  • 1
    With two vastly different ranges, I'd suggest using `grid.arrange` or `arrangeGrob` on two `ggplot` calls and just reducing the spacing between them. But that's my rather naive solution – Punintended Oct 08 '18 at 23:37
  • @Punintended Not a bad idea, but unfortunately I need the state labels on the x-axis and I think doing a grid.arrange and reducing the space will mask them. – Drew Wilkins Oct 08 '18 at 23:46
  • Are you aware of this post: https://stackoverflow.com/questions/38333603/ggplot-custom-scale-transformation-with-custom-ticks – Simon.S.A. Oct 09 '18 at 01:02
  • This sounds like it may be a [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Are you actually looking for a way to visualise your data without masking x-axis labels? If so, make that the focus of your question, with a fuller data sample that reflects the range of your data, and you may get more useful answers. – Z.Lin Oct 09 '18 at 05:02

0 Answers0