0

I want to use an image as a node in a .dot program embedded into an Rmarkdown project. I can't figure out how to get an image file to appear in the output using DiagrammeR. Nodes and HTML-Like labels seem to work, just not the IMG attribute.

Below is my code so far:

digraph structs {

  struct1 [shape=none, label=
    <<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" POINT-SIZE=\"8\"> 
      <TR>
        <TD ROWPAN=\"2\">
          <FONT POINT-SIZE=\"16\">
            Car
          </FONT>
        </TD>
      </TR>
      <TR>
        <TD></TD>
      </TR>
      <TR>
        <TD>
          <FONT POINT-SIZE=\"10\">
            Engine Size
          </FONT>
        </TD>
      </TR>
      <TR>
        <TD>
          <FONT POINT-SIZE=\"10\">
            Paint Job
          </FONT>
        </TD>
      </TR>
      <TR>
        <TD></TD>
      </TR>
      <TR>
        <TD>
          <FONT POINT-SIZE=\"10\">
            AutoDrive ()
          </FONT>
        </TD>
      </TR>
    </TABLE>>
    ];

  car1 [shape=none, label=\"\", image=\"../resources/images/car-clip-art.png\"];

<-- This doesn't work either. And this comment is *not* in the program -->
car1 [label=
<<TABLE> 
<TR>
  <TD>
    <IMG SCALE=\"FALSE\" SRC=\"../resources/images/car-clip-art.png\"/>
  </TD>
</TR>
</TABLE>>
];

  struct1->car1
}

Here's the output image:

output of dot code

How can I get the image to show up in the output?

Lancophone
  • 310
  • 2
  • 17
  • I've resorted to just creating the graphics using `dot.exe` by installing graphviz, then including the output in my Rmarkdown file using `knitr::include_graphics()`. This is annoying though as it introduces the extra dependency. I'd rather stay completely in an R environment – Lancophone Jul 03 '19 at 17:13

1 Answers1

0

Maybe the version of the graphviz library loaded by R doesn't have image loading capabilities. Can you find it, and look through its symbols (using whatever tool is appropriate on Windows) to see what flavors of loadimage() are defined? e.g. gd_loadimage, cairo_loadimage, gdiplus_loadimage etc. Also try converting the image to JPEG as it is usually the rock bottom lowest common denominator in image formats (or else GIF).

Also try a different file path or an absolute path or a path with no directories, in case there is some misunderstanding about path syntax. I wonder if the path separator is "/" or "\" in Windows. Of course many programs are flexible about this. I believe our code just hands off to a lower level library for this.

I'm not sure about all the escapes and nested <> in your example but it sounds as if have this figured out already and that it must be correct.

Stephen North