1

I am trying to use the undercase omega symbol in my R ggplot2 figure legend. I have attempted to use the function sub() to substitute the "w" in my data with the unicode character for undercase omega. However, when I print the vector or data frame w is replaced with "ω".

Example code:

taxa <- c('16w.1', '18w.2.3w6', '15')
count<- c(21, 23, 27)
microbe.data <- data.frame(taxa, count)
my_labels <- sub(pattern = "w", replacement = "\U03C9", x = microbe.data$taxa)

my outcome:

"16ω.1"     "18ω.2.3w6" "15"   

Has anyone else run into this issue, any advice?

Nathan Werth
  • 5,093
  • 18
  • 25
Rebecca
  • 21
  • 2
  • 1
    Take a look at the links next to your question. There are a lot of them asking about greek letters in `ggplot2` figures. – lmo Sep 06 '17 at 19:34
  • Here's one that might help on Greek letters in `ggplot`. https://stackoverflow.com/a/5294214/8382207 – Sagar Sep 06 '17 at 19:36
  • 1
    What version of R are you running and what is the output from `Sys.getlocale()`? (When I run your code I get lowercase omegas.) – joran Sep 06 '17 at 19:41
  • 1
    Try setting `Encoding(my_labels) <- "UTF-8"`. I'm guessing you are on windows with UTF-8 encoding is not the default. – MrFlick Sep 06 '17 at 19:55
  • @MrFlick I'm on Windows and your tip solved it. – Rui Barradas Sep 06 '17 at 20:03
  • Thank you MrFlick this was it! – Rebecca Sep 06 '17 at 20:07
  • Thank you all for your help. Thanks Imo, I have learned a lot from the links when I was searching for help but couldn't directly answer my question. Thank you for your patience. – Rebecca Sep 06 '17 at 20:08
  • Thank you joran, I had tried re-installing R and rstudio a few days ago, just to be safe. – Rebecca Sep 06 '17 at 20:09

0 Answers0