Magdalena A. Tkacz
2012-Oct-07 16:07 UTC
[R] Problem with national characters in main, xlab, ylab with pdf{grDevices} / postscript {grDevices}
Hello. I'm trying to make some graphics with nationalized labels (pdf for use in LaTeX document). On console (displayed on screen) using all looks ok: ----------------------------------------\/ data<-rnorm(100) hist(data,main='Rozk?ad g?sto?ci punkt?w', xlab='Warto?? na osi y', ylab='Cz?sto?? wyst?powania') -------------------------------------------/\ But using: -------------------------------------------\/ data<-rnorm(100) pdf('plik.pdf',encoding="CP1250.enc") hist(data,main='Rozk?ad g?sto?ci punkt?w', xlab='Warto?? na osi y', ylab='Cz?sto?? wyst?powania') dev.off() --------------------------------------------/\ It does not look fine ... Without specifying encoding: -------------------------------------------\/ pdf('plik-wo-enc.pdf') hist(data,main='Rozk?ad g?sto?ci punkt?w', xlab='Warto?? na osi y', ylab='Cz?sto?? wyst?powania') dev.off() ---------------------------------------------/\ Almost does not have national characters. (Almost, because "?" letter appears) Exemplary pdf file are here: https://www.drivehq.com/file/df.aspx/shareID10318887/fileID1167942261/plik.pdf https://www.drivehq.com/file/df.aspx/shareID10318887/fileID1167945977/plik-wo-enc.pdf I have read "Non-Standard Fonts in PostScript and PDF Graphics" by Paul Murrell and Brian Ripley in Rnews. I have also tried option with -------------------\/ Sys.setlocale(category="LC_CTYPE", locale="pl_PL.utf8") -------------------/\ but even in admin (run R as admin) in Win7 I received warning: -------------------\/ "In Sys.setlocale(category = "LC_CTYPE", locale = "pl_PL.utf8") : ??dania raport?w OS aby ustawi? lokalizacj? na "pl_PL.utf8" nie mog? zosta? wykonane" -------------------/\ (translated in short : OS report request to set locale to "pl_PL.utf8" can not be done) Does anyone knows how to obtain pdf documents with acceptable quality? Thanks in advance, Regards -- /|/| _ _ _/_ /_ _ / / _ __ / |(/(/(/(/((-/)(/ ( /((/( /_ _/ Magdalena Tkacz
Prof Brian Ripley
2012-Oct-07 17:40 UTC
[R] Problem with national characters in main, xlab, ylab with pdf{grDevices} / postscript {grDevices}
'National': not my nation, and none is stated. Somewhere in Eastern Europe ... Poland? Short answer: you need to use a family which contains those glyphs (try family='NimbusSan': the default 'Helvetica' does not) *and* a viewer that uses fonts that do. Longer answer: read ?pdf and ?postscript carefully, as they told you this and more. Your example works correctly with that family for me on Linux, but not with OS X viewers. It does not with the default family. For people on Unix I would suggest the cairo_pdf() device as a possibly easier alternative since it usually embeds fonts. On Windows and OS X you are at the mercy of what fonts cairo has access to. That's all in the help, too. On Sun, 7 Oct 2012, Magdalena A. Tkacz wrote:> Hello. > > I'm trying to make some graphics with nationalized labels (pdf for use > in LaTeX document). > > > On console (displayed on screen) using all looks ok: > ----------------------------------------\/ > data<-rnorm(100) > hist(data,main='Rozk?ad g?sto?ci punkt?w', xlab='Warto?? na osi y', > ylab='Cz?sto?? wyst?powania') > -------------------------------------------/\ > > But using: > -------------------------------------------\/ > data<-rnorm(100) > > pdf('plik.pdf',encoding="CP1250.enc") > hist(data,main='Rozk?ad g?sto?ci punkt?w', xlab='Warto?? na osi y', > ylab='Cz?sto?? wyst?powania') > dev.off() > --------------------------------------------/\ > > It does not look fine ...Actually it is just a binary file, and no viewer has been mentioned.> > Without specifying encoding: > -------------------------------------------\/ > pdf('plik-wo-enc.pdf') > hist(data,main='Rozk?ad g?sto?ci punkt?w', xlab='Warto?? na osi y', > ylab='Cz?sto?? wyst?powania') > dev.off() > ---------------------------------------------/\ > Almost does not have national characters. (Almost, because "?" letter appears) > > Exemplary pdf file are here: > https://www.drivehq.com/file/df.aspx/shareID10318887/fileID1167942261/plik.pdf > https://www.drivehq.com/file/df.aspx/shareID10318887/fileID1167945977/plik-wo-enc.pdf > > > I have read "Non-Standard Fonts in PostScript and PDF Graphics" by > Paul Murrell and Brian Ripley in Rnews. > > I have also tried option with > -------------------\/ > Sys.setlocale(category="LC_CTYPE", locale="pl_PL.utf8") > -------------------/\ > but even in admin (run R as admin) in Win7 I received warning: > -------------------\/ > "In Sys.setlocale(category = "LC_CTYPE", locale = "pl_PL.utf8") : > ??dania raport?w OS aby ustawi? lokalizacj? na "pl_PL.utf8" nie mog? > zosta? wykonane" > -------------------/\ > (translated in short : OS report request to set locale to "pl_PL.utf8" > can not be done) > > > Does anyone knows how to obtain pdf documents with acceptable quality? > > > > Thanks in advance, > > Regards > > -- > /|/| _ _ _/_ /_ _ / / _ __ > / |(/(/(/(/((-/)(/ ( /((/( /_ > _/ > Magdalena Tkacz > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595