1

I have this dataframe called cpp. I have plotted the figure below which is missing X-axis in two of the plots in the right. How can I put the x-axis for these two plots? Additionally, I would also like to increase the size of each box,so the lines would not touch the margin on the right.

ggplot(cpp, aes(x = Num_Good, y = IBS, group = key.related.sheet, color = cutoff)) +
  geom_line() + facet_wrap(~cutoff) + geom_point()

enter image description here

Axeman
  • 32,068
  • 8
  • 81
  • 94
MAPK
  • 5,635
  • 4
  • 37
  • 88
  • 2
    This is a known issue: https://github.com/hadley/ggplot2/issues/1607 – mtoto Sep 12 '16 at 08:18
  • You might get it to work by installing one of the development branches with `devtools::install_github('thomasp85/ggplot2', ref = 'ggproto-facets')`. – Axeman Sep 12 '16 at 10:02

1 Answers1

3

Check this answer about the "dangling" facets: add "floating" axis labels in facet_wrap plot

Or as a quick workaround (if it is ok to add x axis to all facets), you can set the parameter scales = "free_x" of facet_wrap.

Regarding the second part of your question, try to set the second value of the expand parameter in scale_x_continuous, e.g.:

ggplot(cpp, aes(x = Num_Good, y = IBS, group = key.related.sheet, color = cutoff))+
  geom_line() + 
  facet_wrap(~cutoff, scales = "free_x") + 
  geom_point() +
  scale_x_continuous(expand = c(0, .1))
Community
  • 1
  • 1
Tamas Nagy
  • 1,001
  • 12
  • 22