[英]Save graph with emojis in label as pdf in R
Using the top answer here:在这里使用最佳答案:
How to export images of diagrammer in R 如何在 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我设法将一个.dot
文件导入 R ,然后使用以下行将包含名称和箭头的图形的可视 plot 导出为 pdf
# 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. .dot
文件中的label
字段包含表情符号的代表国家/地区。 Here is a small portion of the .dot
file below:下面是.dot
文件的一小部分:
/* 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.当我使用上面的代码将图形转换为 pdf 时,表情符号不会出现在最终的 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?有没有办法将图形从包含 label 中的表情符号的.dot
文件转换为仍会显示表情符号的 pdf?
Using the comment by @charlie-gallagher , I was able to figure out a solution.使用@charlie-gallagher的评论,我找到了解决方案。
The first step is to export the full graph (with text labels, arrows, etc.) directly as an .svg
.第一步是将完整的图形(带有文本标签、箭头等)直接导出为.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.创建.svg
文件后,我只是使用另一个应用程序将 svg 转换为 pdf。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.