r - Extrafont and ggsave: Characters end up on top of another -


i'm trying use arial.ttf in plots. have found several manuals fonts online, i'm running issues when try save pot via ggsave , default device.

minimal working example

i'm running following minimal working example reproduce bug:

sys.setenv(r_gscmd="d:/gs/bin/gswin64c.exe")  library(ggplot2)  require(extrafont) font_import(prompt = f, pattern = "arial.ttf") font_import(prompt = f, pattern = "jokerman.ttf") loadfonts(device="win", quiet = t) loadfonts(device="pdf", quiet = t)  plot <- ggplot(mtcars, aes(wt, mpg, colour = hp)) + geom_point() jokerman_plot <- plot + theme_bw(base_family = "jokerman") arial_plot <- plot + theme_bw(base_family = "arial")  ggsave("arial_plot.png", arial_plot) ggsave("arial_plot.pdf", arial_plot) embed_fonts("arial_plot.pdf")  ggsave("jokerman_plot.png", jokerman_plot) ggsave("jokerman_plot.pdf", jokerman_plot) embed_fonts("jokerman_plot.pdf") 

this results in following (correct) png images:

correct arial plot correct jokerman plot

the arial pdf has characters stacked ontop of each other (the jokerman pdf renders correct):

jumbled plot

warning output

the following warning messages generated script.

warning messages: 1: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x68 2: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x70 3: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font metrics unknown character 0x4d 4: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x68 5: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x70 6: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x4e 7: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x41 8: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font metrics unknown character 0x4d 9: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x31 10: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 11: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 12: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x31 13: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x35 14: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 15: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x32 16: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 17: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 18: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x32 19: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x35 20: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 21: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x33 22: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 23: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 24: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x4e 25: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x41 26: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x4e 27: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x41 28: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x31 29: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 30: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 31: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x31 32: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x35 33: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 34: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x32 35: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 36: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 37: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x32 38: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x35 39: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 40: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x33 41: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 42: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x30 43: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x4e 44: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x41 45: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x6d 46: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x70 47: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x67 48: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font metrics unknown character 0x4d 49: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x6d 50: in grid.call(l_textbounds, as.graphicsannot(x$label),  ... :   font width unknown character 0x70 

session info

my current sessioninfo()

r version 3.3.0 (2016-05-03) platform: x86_64-w64-mingw32/x64 (64-bit) running under: windows >= 8 x64 (build 9200)  locale: [1] lc_collate=german_germany.1252  lc_ctype=german_germany.1252    lc_monetary=german_germany.1252 [4] lc_numeric=c                    lc_time=german_germany.1252      attached base packages: [1] stats     graphics  grdevices utils     datasets  methods   base       other attached packages: [1] extrafont_0.17      ggplot2_2.1.0       revoutilsmath_3.2.5  loaded via namespace (and not attached):  [1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     assertthat_0.1   plyr_1.8.3       tools_3.3.0       [7] gtable_0.2.0     ggthemes_3.0.3   rcpp_0.12.5      extrafontdb_1.0  grid_3.3.0       digest_0.6.9     [13] rttf2pt1_1.3.4   munsell_0.4.3   

attempted solutions

  • i've tried several ways of renaming generated amf files no avail
  • i've thought maybe encoding of source file might matter, changed utf-8 (no change)
  • resetting extrafontdb multiple times
  • reinstalling ghostscript multiple times

workarounds

i have 2 workarounds, prefer use "native" pdf device configured in r or ggplot portability sake

  1. specify cairo_pdf device (this can cause secondary issues output or plots render different). pdf fine, point bug in default pdf device?
  2. use png/bitmap output (i want use plots in print, vector output preferred)
  3. rely on r using arialmt default. i'm not sure if arialmt same font used in (latex) document, specify font explicitely.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -