Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X axis doesn't appear below facet_wrap plot with uneven number of facets #1607

Closed
paulrougieux opened this issue Apr 8, 2016 · 1 comment
Closed
Labels
Milestone

Comments

@paulrougieux
Copy link

@paulrougieux paulrougieux commented Apr 8, 2016

When drawing a plot with facet_wrap. If there is an uneven number of facets, the x axis is not drawn for facets which do not touch the "floor" of the plotting area. For example

ggplot(airquality, aes(x = Day, y = Temp)) +
    facet_wrap(~Month) + 
    geom_line()

airquality_facet_wrap

It's possible to add an axis under all plots by setting the scales argument to "free_x".

ggplot(airquality, aes(x = Day, y = Temp)) +
    facet_wrap(~Month, scales = "free_x") + 
    geom_line()

airquatlity_facet_wrap_free_x

But it's not possible to add an x axis only for the last dangling plot alone. This axis could be located in two places, right below the dangling plot:

airquality_facet_wrap_dangling_above

or at the bottom of the plotting area:

airquality_facet_wrap_dangling_below

A workaround was given in this Stackoverflow answer. The author said a suggestion could be submitted here. 2 years after those comments were made on Stackoverflow, no suggestion has been submitted here on github. Considering the number of votes on the workaround answer, the issue still attracts interest. I thought I'd request your feedback. Could this feature be implemented, with minimal change to ggplot2, or is this out of the question?

@paulrougieux paulrougieux changed the title X axis appears below facet_wrap plot with uneven number of facets X axis doesn't appear below facet_wrap plot with uneven number of facets Apr 8, 2016
@hadley hadley added this to the v2.2.0 milestone Jul 28, 2016
@hadley hadley closed this Sep 20, 2016
@paulrougieux
Copy link
Author

@paulrougieux paulrougieux commented Nov 9, 2016

This issue has now been fixed in the development version of ggplot2. To those coming from the Stackoverflow question and wondering how to get this version. You need the devtools packages.

install.packages("devtools")

Devtools installs packages directly from a github repository instead of from CRAN.
You also need to install the development version 0.4.1. of the scales packages:

devtools::install_github("hadley/scales")
devtools::install_github("tidyverse/ggplot2")

Then try to generate the example plot I reported in my issue:

library(ggplot2)
ggplot(airquality, aes(x = Day, y = Temp)) +
       facet_wrap(~Month) + 
       geom_line()

This plot should have an x axis under each of the 3 panels.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants