Getting greek character in plot axis [duplicate]

2019-07-29 09:47发布

问题:

This question already has an answer here:

  • Adding greek character to axis title 5 answers

I am making barplots for different metal concentration in various materials, and need the axis to say μg/g. I've searched for how to implement greek characters into different plots, but I don't seem able to actually do so. It looks like I should be able to use (expression(paste)) - can anyone help me?

This is an extract of my current script:

BP.Ag <- ggplot(data=dat, aes(x=Material, y=Ag, fill=Sample.Material)) +  
  geom_bar(stat="identity", position="dodge") + theme_bw() + 
  scale_fill_brewer(palette = "Set1") + ylab("Silver (μg/g)") + guides(fill=FALSE) + theme(axis.text.x = element_text(angle = 45, hjust = 1))

Thanks!

回答1:

Have you tried the UTF-8 for µ ("\u00B5"):

>cat("\u00B5")
µ

In your plot you could use:

ylab("Silver (\u00B5g/g)")


回答2:

A similar question was asked here: Adding greek character to axis title

Your ylab should be something like +ylab(expression(paste("Silver ", mu,"g/g")))