0

Using the top answer here:

How to export images of diagrammer in R

I managed to import a .dot file into R and and then export a visual plot of the graph containing names and arrows as a pdf using the lines


# setwd("/Folder with .dot graph file")

library(DiagrammeR)
library(DiagrammeRsvg)

DiagrammeR::grViz("mygraph.dot") %>%
  export_svg %>% charToRaw %>% rsvg_pdf("graph.pdf")

The label field in the .dot file contains emoji's representing countries. Here is a small portion of the .dot file below:

/* Created by igraph 1.2.6 */
digraph {
  0 [
    name=1
    type=NA
    label="A name\n"
    shape=note
    color=Black
    fillcolor=White
    style=filled
  ];
  1 [
    name=2
    type=NA
    label="Another Name\n"
    shape=note
    color=Black
    fillcolor=White
    style=filled
  ];
.
.
.
1 -> 0 [
    rel=a
    "type.x"=NA
    "type.y"=NA
  ];
2 -> 0 [
    rel=a
    "type.x"=NA
    "type.y"=NA
  ];
.
.
.
}

When I use the code above to convert the graph to a pdf, the emoji's do not appear in the final pdf.

Is there a way to convert a graph from a .dot file containing emoji's in the label into a pdf which will still display the emojis?

NM_
  • 1,887
  • 3
  • 12
  • 27
  • 1
    Maybe this has something to do with PDF? See [this Adobe answer](https://community.adobe.com/t5/acrobat/emoji-in-adobe-pdf/td-p/10148087?page=1). The author suggests a workaround like rasterizing or vectorizing. Not sure how to do that in R here. Do emojis normally print when you convert to pdf? – Charlie Gallagher Jan 02 '21 at 23:01
  • It seems to work for me with your minimal example dot file (removing the rows with only colons). I am on R-devel with DiagrammR v. 1.0.6.1, DiagrammRsvg 0.1 and rsvg 2.1. I get rasterized flags in the pdf output. Maybe upgrading to development versions of (one of?) these packages might help, or there are other issues in your full dot file that do not show up with the truncated version. – user12728748 Jan 03 '21 at 00:32
  • @CharlieGallagher Thank you for the information, using the information in the thread I was able to figure out a solution – NM_ Jan 03 '21 at 22:21

1 Answers1

1

Using the comment by @charlie-gallagher, I was able to figure out a solution.

The first step is to export the full graph (with text labels, arrows, etc.) directly as an .svg.

svg = export_svg(grViz("mygraph.dot"))
write(svg, "mygraph.svg")

After the .svg file is created, I just used another application to convert the svg to a pdf.

NM_
  • 1,887
  • 3
  • 12
  • 27