archetypitect
archetypitect

Reputation: 13

Shifting facet titles higher in ggplot

When splitting a basic bar plot with facet_wrap, the strip titles are drawn behind and barely above the plot area, meaning any character descenders are cut off. Is there a way I can space these a little? The problem persists whether or not I use ggthemr.

Thanks!

Example of what I'm talking about:

enter image description here

Upvotes: 1

Views: 272

Answers (1)

MichaelVE
MichaelVE

Reputation: 1344

You can specify the margins of the element by adding it in the strip.text.x argument, as follows:

A = data.frame(x = 1:4, y = 1:4, z = c('A','A','B','B'))

ggplot(A) +
  geom_point(aes(x = x, y = y)) +
  facet_wrap(~z) +
  theme_bw()+
  theme(strip.text.x = element_text(margin = margin(2,0,2,0, "cm")))

Upvotes: 2

Related Questions