2

I have the following data:

thedata <-  data.frame(value= c(90,100,2,10)
                       ,category1 = c("A","A","B","B")
                       ,category2 = c("C","D","C","D"))

And I am looking to produce the following figure with labels just to the outside of the bars:

ggplot(thedata, aes(x=category2, y=value)) + 
  geom_bar(stat="identity", position="dodge", fill = "grey") +
  facet_wrap(~category1, scales = "free_x") +
  coord_flip() +
  geom_text(aes(label=value, hjust = -0.35))

enter image description here

Using this method the labels fall outside the chart range. If the expand_limits argument is used it overwrites the scales = "free_x" argument. Any suggestions for say, adding an extra 10% space to each of the chart to accommodate the labels?

SlyGrogger
  • 317
  • 5
  • 16

1 Answers1

1

Use the expand argument of scale_y_continuous. See ?continuous_scale for details.

Ista
  • 10,139
  • 2
  • 37
  • 38
  • To add space in just one direction see the new `expand_scale()` function (as of ggplot2 3.0.0). You can see an example [here](https://stackoverflow.com/a/48678947/2461552). – aosmith Jul 13 '18 at 15:30
  • Thanks, if I add argument `scale_y_continuous(expand = c(0.1, 0))` then that does the trick! – SlyGrogger Jul 13 '18 at 15:35