2

I can't seem to display greek letters in r. I'm working with RStudio, and I can't seem to display greek characters no matter what I try. Initially I tried to display greek letters inside bquote, using syntax from a class I took, which the prof. published and demonstrated it worked in class. When all it showed was squares**, I tried more basic ways of displaying greek letters. I tried to use expression and than I tried to find the simplest way and ran this syntax which I found online:

mycoef <- rnorm (1000)
hist(mycoef, main = expression(beta))

In all cases it either display a square (like an unrecognized symbol), or just the word (beta, chi, etc.,). This syntax also displayed a square using R instead of RStudio.
I tried to change a bit the encoding of the file (ASCII/UTF-8), but this didn't change anything. I am working on a mac (macOS Sierra 10.12.4) if that changes anything.

**when using the bquote syntax, greek letters were not the only characters it changed to squares. Also == and ~~ without quotes were displayed as squares.

This is my sessionInfo() -
R version 3.4.2 (2017-09-28) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Sierra 10.12.4

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale: [1] pt_PT.ISO8859-1/pt_PT.ISO8859-1/pt_PT.ISO8859-1/C/pt_PT.ISO8859-1/C

attached base packages: [1] grid stats graphics grDevices utils datasets methods base

other attached packages: [1] plyr_1.8.4 meta_4.8-4 openxlsx_4.0.17

loaded via a namespace (and not attached): [1] compiler_3.4.2 tools_3.4.2 Rcpp_0.12.13

=====
Note that as a try to fix this problem I ran this syntax that is displayed in the sessionInfo - Sys.setlocale("LC_ALL", "pt_PT.ISO8859-1"), which didn't help.

Thanks!

NoamMm
  • 21
  • 1
  • 3

2 Answers2

0

You can try using package latex2exp if you know the basics of LaTeX:

library(latex2exp)

mycoef <- rnorm (1000)
hist(mycoef, main = TeX("$\\beta$"))
Samuel
  • 2,895
  • 4
  • 30
  • 45
  • Unfortunately this hasn't resolved the problem. But thanks. – NoamMm Oct 17 '17 at 20:32
  • 1
    In RStudio, make sure Tools --> Global Options --> Code --> Saving --> "Default text encoding" is set to UTF-8. – Samuel Oct 17 '17 at 21:10
  • In MacOS: Open Terminal --> Preferences --> Advanced --> Text encoding --> Unicode (UTF-8). – Samuel Oct 17 '17 at 21:26
  • The preferences in Terminal were already set to UTF-8. I changed the settings following your recommendation in RStudio, but unfortunately this hasn't change anything. Thanks anyways. – NoamMm Oct 19 '17 at 20:01
0

I solved this problem updating the Symbols Font on Windows. (1) Download the file Symbol.ttf (https://www.fontsupply.com/fonts/S/Symbol.html), (2) Find the file symbol.ttf in your \Windows\Fonts folder, and replace with the fresh copy.

Hernan
  • 1