Yes, but I should acknowledge my ignorance in not realizing that "\u00b0" (hex 176) is a simpler way to get the character in R without the OS tool than intToUtf8() . If you need math notation beyond simple symbol characters, plotmath is certainly indispensable.
Bert On Tue, Nov 30, 2021 at 7:51 PM Andrew Simmons <akwsi...@gmail.com> wrote: > Using the degree character seems perfectly legit to me. The reason I > suggest looking at plotmath is that I think plotmath is easier to read > (that is, if you're escaping your characters with \u), and because for > anything more complicated like set notation, big sums, integrals, you'll > need to get used to plotmath to make your labels. Either way, nice > suggestion, both work perfectly well for this situation > > On Tue, Nov 30, 2021, 16:24 Bert Gunter <bgunter.4...@gmail.com> wrote: > >> True, but unnecessary with UTF-8 encodings of unicode (subject to some >> caveats, though): >> >> plot(1:5, runif(5),xlab = "Temp (°F)", ylab = "result") >> >> should work fine, where the º ("degree") symbol was inserted by the >> symbol insertion facility on my Mac. Windows has something similar. >> See the comments in the plotmath documentation just before the >> examples for more details on this, along with some caveats about the >> need for a suitable display/plot device. >> >> More laboriously, but perhaps more informatively, one can look up >> "unicode code point for degree symbol" to find that it is decimal 176. >> Then R's intToUtf8() function converts this to the UTF-8 encoding that >> **should** display as a "degree" symbol, subject to the above >> referenced caveats. >> Hence: >> > intToUtf8(176) >> [1] "°" ##degree character >> >> ## So, for example, you can do: >> > degrF <-paste0(intToUtf8(176),"F") >> > degrF >> [1] "°F" ("degrees F") >> >> > plot(1:5, runif(5),xlab = paste0("Temp (", degrF,")"), ylab = "result") >> >> As Andrew said, you can use plotmath to do this, too; it just isn't >> needed for simple insertion of "standard" symbols. >> >> NOTE: As I am far from an expert on all of this, I would appreciate >> clarification or correction of any errors or misstatements in the >> above. >> >> Bert Gunter >> >> >> On Tue, Nov 30, 2021 at 11:34 AM Andrew Simmons <akwsi...@gmail.com> >> wrote: >> > >> > Excuse my brevity, but take a look at ?plotmath >> > >> > It has tons of tips for making pretty labels >> > >> > On Tue, Nov 30, 2021, 14:05 Rich Shepard <rshep...@appl-ecosys.com> >> wrote: >> > >> > > 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 >> > > >> > > ______________________________________________ >> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > > https://stat.ethz.ch/mailman/listinfo/r-help >> > > PLEASE do read the posting guide >> > > http://www.R-project.org/posting-guide.html >> > > and provide commented, minimal, self-contained, reproducible code. >> > > >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.