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?
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.