can I change the position of the strip label in ggplot from the top to the bottom?

RGgplot2StripFacet

R Problem Overview


I know this is not quite a data visualization issue, but the boss asked for it, so I need to figure out if it is possible.

Thanks!

R Solutions


Solution 1 - R

An answer for those searching in 2016.

As of ggplot2 2.0, the switch argument will do this for facet_grid or facet_wrap:

> By default, the labels are displayed on the top and right of the plot. If "x", the top labels will be displayed to the bottom. If "y", the right-hand side labels will be displayed to the left. Can also be set to "both".

ggplot(...) + ... + facet_grid(facets, switch="both")

As of ggplot2 2.2.0,

> Strips can now be freely positioned in facet_wrap() using the strip.position argument (deprecates switch).

Current docs, are still at 2.1, but strip.position is documented on the dev docs.

> By default, the labels are displayed on the top of the plot. Using strip.position it is possible to place the labels on either of the four sides by setting strip.position = c("top", "bottom", "left", "right")

ggplot(...) + ... + facet_wrap(facets, strip.position="right")

Solution 2 - R

you can now use facet_wrap(~var, strip.position = "bottom"), though for some reason this results in the labels being located above the axis tick mark labels, rather than below (which I think would make more sense), as you can see from my screenshot of a small portion of my graph

screenshot of graph

If you want to have the label below, you have do to this

ggplot(zzz, aes(x = c1, y = c2)) +
  facet_wrap(~ gp, scales = "free", nrow = 3, strip.position = "bottom") +
  geom_point() +
  theme(
    aspect.ratio = 1,
    strip.background = element_blank(),
    strip.placement = "outside"
  )

As seen here: https://github.com/tidyverse/ggplot2/issues/2622

Solution 3 - R

The answer is yes!

theme(strip.text=element_text(vjust=-10))

The number -10 is determined by the scale and units you're using in your plot.

Solution 4 - R

To follow on the use of theme:

> theme(strip.text=element_text(vjust=-10))

Be sure your labels all have the same number of carriage returns.

Label /n Facet /n One will vjust at a different rate than Label /n Facet Two.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlokheartView Question on Stackoverflow
Solution 1 - RDaveView Answer on Stackoverflow
Solution 2 - RludaView Answer on Stackoverflow
Solution 3 - RbrainSciView Answer on Stackoverflow
Solution 4 - RMark WagnerView Answer on Stackoverflow