Changing background height of stripe text in ggplot2 does not work properly

###Load libraries library(ggplot2) library(gtable) ###Build plot d <- ggplot(mtcars, aes(x=gear)) + geom_bar(aes(y=gear), stat="identity", position="dodge") + facet_wrap(~cyl) ###Change height of strip text g <- ggplotGrob(d) g$heights[[3]] = unit(2,"in") grid.newpage() grid.draw(g) 

The result ( ggplot2_2.0.0 )

enter image description here

Expected Result ( ggplot2_1.0.1 )

enter image description here

Question

What is going on here in middle earth?

+5
source share
1 answer

It looks like a trick

 g <- ggplotGrob(d) g$heights[[3]] = unit(2,"in") g$grobs[[5]]$heights <- g$grobs[[6]]$heights <- g$grobs[[7]]$heights <- unit(1, "native") # or "npc" grid.newpage() grid.draw(g) 

enter image description here

It also works if you replace unit(1, "native") with a positive number or TRUE (I'm not sure why, though - maybe at some point this is forcibly applied to the default type module, probably "npc" )

+5
source

Source: https://habr.com/ru/post/1241639/


All Articles