Italics in dashboard headings in facet_wrap()

Asked

Viewed 144 times

5

I’m having trouble formatting species names in italics in the title of the panels with the argument facet_wrap in the ggplot2. Following example:

library(ggplot2)
ggplot(mpg, aes(x=displ, y=hwy)) +
  geom_point() +
  geom_smooth(method="lm", se=FALSE, colour="black") +
  facet_wrap(~ trans)

In this example we have as a result 10 panels, each with a title, which are the variables in my original data table. How to put these titles in italics?

  • 4

    Thanks a lot, Marcus! Even asking the question here, I kept trying to find out, and I had already thought that the way would be through strip.text, I just hadn’t got the code formatting right.... Thank you very much!!

  • It’s great to know that my response has helped you in some way. So consider vote and accept the answer, so that in the future other people who experience the same problem have a reference to solve it.

1 answer

5

No help from function ggplot2::theme, it is possible to find the argument strip.text. His description is as follows:: facet labels (element_text(); inherits from text). So just change the option to strip.text inside theme to obtain the desired result:

library(ggplot2)
ggplot(mpg, aes(x=displ, y=hwy)) +
  geom_point() +
  geom_smooth(method="lm", se=FALSE, colour="black") +
  facet_wrap(~ trans) +
  theme(strip.text = element_text(face = "italic"))

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.