Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting symbols fails in PDF

I have the following code to create a plot. On the x- and y-axes there are symbols that appear on the screen, in a JPEG when I save my plot in that format, but not when I save the plot as a PDF.

Is there alternative symbol to my \u2030 that will print in my PDF or another solution to my problem? See examples below of the correct (JPEG format) and the incorrect (PDF) plots .

plot(c(-1,1), c(-1,1), bty = "n", type= "n", las = 1, cex.lab = 1.5, cex.axis = 1.25, main = NULL, 
ylab=expression(paste("Correlation Coefficient (r) for ", delta ^{15},"N"," \u0028","\u2030","\u0029")), 
xlab=expression(paste("Correlation Coefficient (r) for ", delta ^{13},"C"," \u0028","\u2030","\u0029")))
axis(1, at = seq(-1.0, 1.0, by = 0.1), labels = F, pos = 0, cex.axis = 0.05, tcl = 0.25)
axis(2, at = seq(-1.0, 1.0, by = 0.1), labels = F, pos = 0, cex.axis = 0.05, tcl = 0.25)

enter image description hereenter image description here

like image 817
Keith W. Larson Avatar asked Aug 23 '12 16:08

Keith W. Larson


2 Answers

The problem is that your default font does not have "‰" (which I would speak as "per mil") as the glyph that is produced with \u0028. You need to change to a font that does have that glyph:

?pdfFonts

This is what I get with my setup where there is no problem (at least as I understand ti.)

> str(pdfFonts("sans"))
List of 1
 $ sans:List of 3
  ..$ family  : chr "Helvetica"
  ..$ metrics : chr [1:5] "Helvetica.afm" "Helvetica-Bold.afm" "Helvetica-Oblique.afm" "Helvetica-BoldOblique.afm" ...
  ..$ encoding: chr "default"
  ..- attr(*, "class")= chr "Type1Font"
like image 64
IRTFM Avatar answered Sep 20 '22 05:09

IRTFM


You probably have to change the encoding. On my mac this gets me the ‰ sign:

pdf('test.pdf',encoding="MacRoman")
plot.new()
text(0,labels="\u2030")
dev.off()

Look in the ‘enc’ directory of package grDevices for available encodings and try them out.

like image 3
Roland Avatar answered Sep 20 '22 05:09

Roland