[R] Degree symbol as axis label superscript

Rich Shepard r@hep@rd @end|ng |rom @pp|-eco@y@@com
Tue Nov 30 19:57:53 CET 2021


I want to present the temperature on the Y-axis label as 'Water Temperature
(oC)' with the degree symbol as a superscript.

My web search found a couple of methods; one put the entire example string
in the axis label, the other is close, but still incorrect.

Source example:
#define expression with superscript
x_expression <- expression(x^3 ~ variable ~ label)
# The example axis label is:
'X3 variable label' (with the 3 as a superscript)

My use:
# Set degree symbol as superscript in plot's y axis:
y_expression <- expression(^o ~ C)

R's error message:
Error in source("../scripts/all_temp_plots.r") :
   ../scripts/all_temp_plots.r:10:28: unexpected '^'
9: # Set degree symbol as superscript in plot's y axis:
10: y_expression <- expression(^
                                ^

What is the proper way to display a degree symbol in a plot's axis label?

Rich



More information about the R-help mailing list