How to add degree symbol to multiple plot legend entries in R?

Viewed 2527

I know I can add a degree symbol to a plot legend by using expression.

plot(1:5,1:5)
legend('topleft', fill = 'white', legend = expression(5~degree~C))

enter image description here

But How can I do this for multiple legend entries?

I tried the following, but it didn't work:

plot(1:5,1:5)
points(1:5,(1:5) + 0.1, col = 2)
legend('topleft', fill = c('white','red'), legend = paste0(c(5,10), expression(~degree~C)))

enter image description here

Edit: I am more interested in how to do this for many values, not just 2.

Any suggestions on how to do this succinctly and neatly would be greatly appreciated! Thanks!

3 Answers

For ggplot:

ylab(expression(paste("SST (",degree~C,")"))) +
Related