Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 705
lokheart Avatar asked Jul 16 '10 02:07

lokheart


People also ask

How do I reorder facets in R?

To reorder the facets accordingly of the given ggplot2 plot, the user needs to reorder the levels of our grouping variable accordingly with the help of the levels function and required parameter passed into it, further it will lead to the reordering of the facets accordingly in the R programming language.

How do you change a facet label?

Change the text of facet labels Facet labels can be modified using the option labeller , which should be a function. In the following R code, facets are labelled by combining the name of the grouping variable with group levels. The labeller function label_both is used.

How do I change the size of a facet label in ggplot2?

If we want to modify the font size of a ggplot2 facet grid, we can use a combination of the theme function and the strip. text. x argument. In the following R syntax, I'm increasing the text size to 30.

How do you remove facet labels?

Facet labelsSetting strip. text to element_blank() will remove all facet labels. You can also remove the labels across rows only with strip.


1 Answers

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") 
like image 141
Dave Avatar answered Oct 11 '22 11:10

Dave