I want to use bold face only on the first element of my top x axis label (in the facet panel). This can be done using the element_text
function. However, when I do the following, all elements in the facet are turned to "bold", while I only want the first one to be bold.
p3 <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + facet_wrap(~ cyl)
p3 + theme(strip.text.x =
element_text(colour = "white", face = c("bold", "plain", "plain")))
Therefore, in here, I only want the label "4" at the top to be bold.
Using Grob
p3 <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + facet_wrap(~ cyl)
p3 <- p3 + theme(strip.text.x =
element_text(colour = "white", face = c("bold", "plain", "plain")))
grob <- ggplotGrob(p3)
elem <- grob$grobs$strip_t.1
elem
NULL
grid.ls(getGrob(elem, "strip.text.x.text", grep=TRUE))$name
Error in getGrob(elem, "strip.text.x.text", grep = TRUE) : it is only valid to get a child from a "gTree"