Message Boards Message Boards

0
|
1426 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How to set color of Dendrogram lines?

Posted 1 year ago

I'm (still) having trouble setting the color of lines drawn by Dendrogram. They are too faint for the publisher - I would prefer them to be Black.

Here is an example:

enter image description here

sMD =
  {
   {1, {1, 1, 1, 0, 1, 1, 0, 1}},
   {2, {0, 1, 1, 0, 0, 0, 1, 1}},
   {3, {0, 1, 0, 1, 0, 1, 0, 0}},

   {4, {0, 1, 0, 0, 0, 0, 1, 1}},
   {5, {0, 1, 1, 1, 0, 0, 0, 1}},
   {6, {1, 1, 1, 0, 0, 1, 1, 0}},

   {7, {0, 0, 0, 0, 1, 0, 1, 0}},
   {8, {1, 1, 0, 1, 0, 1, 1, 1}}
   };
sMDcount = Length[sMD];

jaccardEdgeDistances = Flatten[
   Table[
    Table[
     {sMD[[i, 1]] \[UndirectedEdge] sMD[[j, 1]], 
      Total[If[# == 0, 0, 1] & /@ (sMD[[i, 2]] - sMD[[j, 2]])]}, (* 
     we are counting mismatches *)
     {j, i + 1, sMDcount}
     ],
    {i, 1, sMDcount - 1}
    ],
   1];
jDhash = CreateDataStructure["HashTable"];
jDhash["Insert", Sort[#[[1]]] -> #[[2]]] & /@ jaccardEdgeDistances;
jDhash["Insert", ReverseSort[#[[1]]] -> #[[2]]] & /@ 
  jaccardEdgeDistances;
jDsup = 100*Max[jaccardEdgeDistances[[;; , 2]]];

elabelSize = 9;
iInches = 7/3;

jdD = Dendrogram[
   sMD[[;; , 1]],
   DistanceFunction -> (If[#1 == #2, 0, 
       If[jDhash["KeyExistsQ", #1 \[UndirectedEdge] #2], 
        jDhash["Lookup", #1 \[UndirectedEdge] #2], jDsup]] &),
   ClusterDissimilarityFunction -> "WeightedAverage",
   BaseStyle -> Directive[FontFamily -> "Arial", Black, elabelSize],
   Axes -> {False, True},
   AxesOrigin -> {5, 0},
   AxesStyle -> Black,
   AspectRatio -> 1.1,
   ImageSize -> {72*iInches, 72*iInches}
   ];
Print[jdD];

faintDendrogramFilename = "FaintDendrogram.jpg";
Print[];
If[! True,
  Print[InputForm[faintDendrogramFilename], " not written"],
  (* else *)
  faintDendrogramFile = 
   FileNameJoin[{appDir, faintDendrogramFilename}];
  Export[faintDendrogramFile, jdD, ImageResolution -> 1200];
  Print["wrote ", InputForm[faintDendrogramFilename]];
  ];
POSTED BY: Richard Frost
2 Replies

Perfect.

enter image description here

POSTED BY: Richard Frost

Hi Richard,

You could post-process the output expression. e.g.

SeedRandom[1];
dg = Dendrogram[RandomInteger[100, 8]]

ReplaceAt[dg, {GrayLevel[_], r___} :> {AbsoluteThickness[2], Black, r}, {1, 1}]

enter image description here

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract