0
$\begingroup$

I have created a labeled digraph and a legend using SwatchLegend.

 transitiontransversion = Labeled[Graph[{
T \[DirectedEdge] T, T \[DirectedEdge] C, T \[DirectedEdge] G,  
T \[DirectedEdge] A,
C \[DirectedEdge] C, C \[DirectedEdge] A, C \[DirectedEdge] T, 
C \[DirectedEdge] G,
G \[DirectedEdge] G, G \[DirectedEdge] A, G \[DirectedEdge] C, 
G \[DirectedEdge] T,
A \[DirectedEdge] A, A \[DirectedEdge] C, A \[DirectedEdge] T, 
A \[DirectedEdge] G
}, EdgeStyle -> {A \[DirectedEdge] A -> {Green, 
   AbsoluteThickness[6], Arrowheads[.05]}, 
 C \[DirectedEdge] C -> {Green, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 G \[DirectedEdge] G -> {Green, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 T \[DirectedEdge] T -> {Green, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 T \[DirectedEdge] C -> {Blue, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 C \[DirectedEdge] T -> {Blue, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 T \[DirectedEdge] G -> {Red, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 T \[DirectedEdge] A -> {Red, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 A \[DirectedEdge] G -> {Blue, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 G \[DirectedEdge] A -> {Blue, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 A \[DirectedEdge] T -> {Red , AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 A \[DirectedEdge] C -> {Red, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 C \[DirectedEdge] A -> {Red, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 C \[DirectedEdge] G -> {Red, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 G \[DirectedEdge] C -> {Red, AbsoluteThickness[6], 
   Arrowheads[.05]}, 
 G \[DirectedEdge] T -> {Red, AbsoluteThickness[6], 
   Arrowheads[.05]}}, VertexSize -> { Large}, 
 VertexStyle -> {A -> Yellow, G -> Yellow, C -> Orange, 
 T -> Orange}, VertexLabels -> {
 A -> 
  Placed[{Text[Style["Adenine", Bold, 20]], 
    adenine}, {Center, {-1, 2}}],
  C -> 
  Placed[{Text[Style["Cytosine", Bold, 20]], 
    cytosine}, {Center, {-1, -1.5}}],
  G -> 
  Placed[{Text[Style["Guanine", Bold, 20]], 
    guanine}, {Center, {2, 2}}],
  T -> 
  Placed[{Text[Style["Thymine", Bold, 20]], 
    thymine}, {Center, {2, -1.5}}]
 }, ImageSize -> 800, 
 PlotLabel -> 
 Text[Style["Molecular Character State Changes", Bold, 30]]], 
 SwatchLegend[{Green, Blue, Red, Yellow, 
 Orange}, {Text[Style["Identity Transformations", Bold, 15]], 
 Text[Style["Transitions", Bold, 15]], 
 Text[Style["Transversions", Bold, 15]], 
 Text[Style["Purine", Bold, 15]], 
 Text[Style["Pyrimidine", Bold, 15]]},  LegendLayout -> "Row"]]

All works as expected. However, when I select the graph object using a mouse right click to save it as a *.png fie, the legend is not included, although the graph itself is nicely rendered as a *.png file.

How does one structure the graph output so that the SwatchLegend also appears in the final saved graphic?

Right-clicking on the Legend, which appears in this case below the bounding box of the graph does not provide the option to save the legend as a graphic.

If an answer to this is present in the documentation, it is well hidden.

$\endgroup$
  • 1
    $\begingroup$ Select all of it before right clicking, or better: use Export. $\endgroup$ – Szabolcs Nov 6 '17 at 15:34
  • $\begingroup$ The label is always placed outside the graphic if one tries to resize. However, you are right Export is the way to go. Thank you. $\endgroup$ – Stuart Poss Nov 6 '17 at 16:14
  • $\begingroup$ You can just select the whole thing the same way as you select text, then use File -> Save Selection As... Confusingly, graphics and "other things you may find in a notebook" behave differently when exporting. It seems that for "other things" there's no right click menu to save to PNG (but you can use Save Selection As...). Legends may show inside or outside of the graphics frame, depending on how you placed them. Below with Legended is outside. I just noticed that you used Labeled, which is always outside. When the legend is inside, it counts as a single graphics ... $\endgroup$ – Szabolcs Nov 6 '17 at 16:38
  • $\begingroup$ ... object, so your way of right clicking works, and it exports at normal size. If it's outside, the union of the legend and the graphics count as an "other thing", so right clicking won't work to export, and with Export it exports at 80% size. You can use this hack to make them export at 100%. Why does this have to be so complicated? I don't know. The 80%/100% thing doesn't matter to most people, but personally I prepare figures to an exact size in centimetres and export to PDF. I hit this annoying problem regularly. $\endgroup$ – Szabolcs Nov 6 '17 at 16:40
  • $\begingroup$ As for right click vs Export, I have gotten used to always using Export due to this annoying bug. $\endgroup$ – Szabolcs Nov 6 '17 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.