5

Basically, I get the plot looking the way I want, with greek letters etc, on the default R plot device, then I switch plot device to create a pdf file and I have 'font' problems.

For example:

> x<- 1:4
> y<-x^2
> plot(x,y)
> text(1,2, "\u03bc") #\u03bc == 'mu'

That all works fine, creating a Greek letter 'mu' on the default R plot device (a graphic window) as desired.

However, when I then switch the plot device to generate a .pdf file:

> pdf()
> plot(x,y)
> text(1,2, "\u03bc")

Gives the following:

Warning messages:
1: In text.default(1, 2, "μ") :
  conversion failure on 'μ' in 'mbcsToSbcs': dot substituted for <ce>
2: In text.default(1, 2, "μ") :
  conversion failure on 'μ' in 'mbcsToSbcs': dot substituted for <bc>
3: In text.default(1, 2, "μ") :
  font metrics unknown for Unicode character U+03bc
4: In text.default(1, 2, "μ") :
  conversion failure on 'μ' in 'mbcsToSbcs': dot substituted for <ce>
5: In text.default(1, 2, "μ") :
  conversion failure on 'μ' in 'mbcsToSbcs': dot substituted for <bc>
> dev.off()

and the resulting plot in the .pdf file has 'mu' replaced with the two dots '..'

I've done some reading of ?pdf and ?pdfFonts and I suspect I need to load a correct font family in the call to pdf()... Any help along these lines appreciated.

Here's some of my system info:

R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-linux-gnu (64-bit)
> search()
[1] ".GlobalEnv"        "package:stats"     "package:graphics" 
[4] "package:grDevices" "package:utils"     "package:datasets" 
[7] "package:methods"   "Autoloads"         "package:base"     
Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
Don Slowik
  • 965
  • 10
  • 18
  • Can't reproduce this with R version 3.0.2. Maybe it's time to update. ;) – lukeA Jan 23 '14 at 20:41
  • The two "dot substituted for .." characters indicate R is receiving your string as UTF-8. Perhaps that gives a clue to the underlying problem. – Jongware Jan 23 '14 at 21:40
  • The "\u03bc" specification of 'mu' works in the default R plot window, just not in the pdf device. The pdf device does succesfully draw text(1,3, expression(mu)), (so it has the Greek fonts) , but I want to bold the 'mu' and expression(bold(mu)) ignores the 'bold()' on both devices, while expression(bold("\u03bc")) gives a good bold on the default device and fails on pdf device. – Don Slowik Jan 23 '14 at 22:49
  • But, yes, Jongware, it seems the fonts are there on pdf device, but it's not handling the "\u03bc" character specification the way the default device can/is. – Don Slowik Jan 23 '14 at 22:54
  • Oh, and, I still have the same problem after I upgraded to: R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" via http://cran.r-project.org/bin/linux/ubuntu/README.html – Don Slowik Jan 23 '14 at 23:00
  • 1
    Have you read this 2011 answer? http://stackoverflow.com/a/5886296/2564301 -- it states R to PDF cannot handle UTF-8 (wide) characters. Perhaps it works for your default font because the 'μ' is also mapped into high ASCII (0xB5 in both Mac and Latin1 encoding). (That said, one might fairly assume it should be there in your **bold** font as well.) – Jongware Jan 23 '14 at 23:15

0 Answers0