How to use italics in R graph axis labels

17,265

Using the example from the documentation of ?visreg I think the functions expression and italic will give you what you need:

fit <- lm(Ozone ~ Solar.R + Wind + Temp,data=airquality)
visreg(fit, xlab="Distance (m)", 
       ylab=expression(italic("Sciurus vulgaris  ") (Presence/Absence)))

Output:

As you can see the y-axis label (only the "sciurus vulgaris") is in italics

enter image description here

Share:
17,265
R Beginner
Author by

R Beginner

Updated on June 08, 2022

Comments

  • R Beginner
    R Beginner almost 2 years

    I'm wondering if anyone can help me. I have plotted the following graph:

    visreg(MOD.1, xlab="Distance (m)", ylab="Sciurus vulgaris (Presence/Absence)",
           xvar="Distance")
    

    And I would like to make just 'Sciurus vulgaris' in italics. Can anyone help?

    Thank you!

  • R Beginner
    R Beginner over 8 years
    Thank you for your incredibly speedy reply! I have managed to do that too but I can't get the '(Presence/Absence)' bit to stay in normal font. I have tried variants of this: ylab=expression(italic("Sciurus vulgaris")), "(Presence/Absence)" But no luck!
  • LyzandeR
    LyzandeR over 8 years
    Ah sorry about that, I misread the question. I have updated the answer.
  • R Beginner
    R Beginner over 8 years
    Thank you so much, I have altered all my graphs and they now read properly!