DiagrammeRsvg icon indicating copy to clipboard operation
DiagrammeRsvg copied to clipboard

How can I save the svg file

Open skanskan opened this issue 7 years ago • 1 comments

On the manual you say export_svg(grViz('digraph{a->b; c->a; c->b; c->d;}')) or but how I save it to a svg file?

skanskan avatar Oct 26 '17 22:10 skanskan

export_svg() returns a character vector, you can use writeLines() to write it to a file.

library(DiagrammeR)
library(DiagrammeRsvg)

svg <- export_svg(grViz("digraph{a->b; c->a; c->b; c->d;}"))
writeLines(svg, "graph.svg")

cat(readLines("graph.svg"), sep = "\n")
#> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
#> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
#>  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
#> <!-- Generated by graphviz version 2.40.1 (20161225.0304)
#>  -->
#> <!-- Title: %0 Pages: 1 -->
#> <svg width="172pt" height="188pt"
#>  viewBox="0.00 0.00 172.00 188.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
#> <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 184)">
#> <title>%0</title>
#> <polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-184 168,-184 168,4 -4,4"/>
#> <!-- a -->
#> <g id="node1" class="node">
#> <title>a</title>
#> <ellipse fill="none" stroke="#000000" cx="27" cy="-90" rx="27" ry="18"/>
#> <text text-anchor="middle" x="27" y="-85.8" font-family="Times,serif" font-size="14.00" fill="#000000">a</text>
#> </g>
#> <!-- b -->
#> <g id="node2" class="node">
#> <title>b</title>
#> <ellipse fill="none" stroke="#000000" cx="54" cy="-18" rx="27" ry="18"/>
#> <text text-anchor="middle" x="54" y="-13.8" font-family="Times,serif" font-size="14.00" fill="#000000">b</text>
#> </g>
#> <!-- a&#45;&gt;b -->
#> <g id="edge1" class="edge">
#> <title>a&#45;&gt;b</title>
#> <path fill="none" stroke="#000000" d="M33.6742,-72.2022C36.7476,-64.0064 40.4616,-54.1024 43.8695,-45.0145"/>
#> <polygon fill="#000000" stroke="#000000" points="47.1685,-46.1853 47.4026,-35.593 40.6142,-43.7274 47.1685,-46.1853"/>
#> </g>
#> <!-- c -->
#> <g id="node3" class="node">
#> <title>c</title>
#> <ellipse fill="none" stroke="#000000" cx="82" cy="-162" rx="27" ry="18"/>
#> <text text-anchor="middle" x="82" y="-157.8" font-family="Times,serif" font-size="14.00" fill="#000000">c</text>
#> </g>
#> <!-- c&#45;&gt;a -->
#> <g id="edge2" class="edge">
#> <title>c&#45;&gt;a</title>
#> <path fill="none" stroke="#000000" d="M69.5196,-145.6621C62.4876,-136.4564 53.5653,-124.7764 45.7117,-114.4953"/>
#> <polygon fill="#000000" stroke="#000000" points="48.2828,-112.0953 39.431,-106.2733 42.72,-116.3446 48.2828,-112.0953"/>
#> </g>
#> <!-- c&#45;&gt;b -->
#> <g id="edge3" class="edge">
#> <title>c&#45;&gt;b</title>
#> <path fill="none" stroke="#000000" d="M78.5104,-144.0535C73.7317,-119.4774 65.1029,-75.1008 59.4634,-46.0974"/>
#> <polygon fill="#000000" stroke="#000000" points="62.878,-45.3208 57.5336,-36.1727 56.0067,-46.6569 62.878,-45.3208"/>
#> </g>
#> <!-- d -->
#> <g id="node4" class="node">
#> <title>d</title>
#> <ellipse fill="none" stroke="#000000" cx="137" cy="-90" rx="27" ry="18"/>
#> <text text-anchor="middle" x="137" y="-85.8" font-family="Times,serif" font-size="14.00" fill="#000000">d</text>
#> </g>
#> <!-- c&#45;&gt;d -->
#> <g id="edge4" class="edge">
#> <title>c&#45;&gt;d</title>
#> <path fill="none" stroke="#000000" d="M94.4804,-145.6621C101.5124,-136.4564 110.4347,-124.7764 118.2883,-114.4953"/>
#> <polygon fill="#000000" stroke="#000000" points="121.28,-116.3446 124.569,-106.2733 115.7172,-112.0953 121.28,-116.3446"/>
#> </g>
#> </g>
#> </svg>

Created on 2019-12-10 by the reprex package (v0.3.0)

krlmlr avatar Dec 10 '19 13:12 krlmlr