Plotting symbols fails in PDF

孤者浪人 提交于 2019-12-01 15:31:23

问题


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)


回答1:


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"



回答2:


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.



来源:https://stackoverflow.com/questions/12096152/plotting-symbols-fails-in-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!