Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the size of the strip on facets in a ggplot?

Tags:

r

ggplot2

Is there any way to control the size of the strips on facets in a ggplot? I tried using strip.background=element_rect(size=n) but as far as I can tell it didn't actually do anything. Is this even possible?

like image 638
iod Avatar asked Dec 10 '14 17:12

iod


People also ask

How to change the size of facet labels in ggplot?

By default, the size of the label is given by the Facets, here it is 9. But we can change the size. For that, we use theme() function, which is used to customize the appearance of plot. We can change size of facet labels, using strip.

How do I rearrange facets in ggplot2?

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.

What is facet wrap in ggplot2?

facet_wrap() makes a long ribbon of panels (generated by any number of variables) and wraps it into 2d. This is useful if you have a single variable with many levels and want to arrange the plots in a more space efficient manner. You can control how the ribbon is wrapped into a grid with ncol , nrow , as.

What is the function of Facet_grid () in Ggplot ()?

facet_grid() forms a matrix of panels defined by row and column faceting variables. It is most useful when you have two discrete variables, and all combinations of the variables exist in the data. If you have only one variable with many levels, try facet_wrap() .


1 Answers

converting the plot to a gtable manually lets you tweak the strip height,

library(ggplot2)
library(gtable)

d <- ggplot(mtcars, aes(x=gear)) + 
            geom_bar(aes(y=gear), stat="identity", position="dodge") +
            facet_wrap(~cyl)

g <- ggplotGrob(d)
g$heights[[3]] = unit(1,"in")

grid.newpage()
grid.draw(g)
like image 145
baptiste Avatar answered Sep 16 '22 18:09

baptiste