2

I want to display pretty dendrograms for some agglomerative clusters I am generating in Java. I write the clusters out to a file in Newick format. Then, I can get a pretty picture that is almost what I want.

tr = phytreeread('myfile.tree')
phytreetool(tr)

enter image description here

Unfortunately, the X axis is not what I want. I would prefer to "reverse" the axis, because the iterations of the clustering progress from right to left, e.g. firstName and setFirstName get clustered in the first iteration. Does anybody know how I can do that, or at least turn off the X axis labeling? (What is the default axis trying to tell me anyway?)

SlowLoris
  • 995
  • 6
  • 28
kc2001
  • 5,008
  • 4
  • 51
  • 92

3 Answers3

2

First, you will need to gain access to the handle for the axes in which the dendrogram is plotted. If it's the only figure open, you can use the function FINDALL like so:

phyAxes = findall(0,'Type','axes');

Now, what you want to change isn't the x-axis direction, since this will reverse the plotted dendrogram as well. You actually want to change just the labels used for the x-axis tick marks. If you want to just turn them off, you can do this:

set(phyAxes,'XTick',[]);

Now, I'm not sure what the x-axis is meant to tell you. In your example, it appears that each branch point is positioned at an integer value along the x-axis starting at 0 for the left-most branch point (the "root", I guess). The right-most branch containing firstName and setFirstName is positioned at a value of 21. If you want to change the axis labeling so that the right-most branch is at 0 and the left-most branch is at 21, you can modify the axes as follows:

set(phyAxes,'XTick',0:21,'XTickLabel',num2str((21:-1:0).'));
gnovice
  • 125,304
  • 15
  • 256
  • 359
0

This could help you?

set(gca,'XDir','reverse')

EDIT You may find a lot of interesting here. Cheers!

Igor
  • 2,619
  • 6
  • 24
  • 36
  • It looked so promising... After various failed attempts at getting the right syntax, I managed to change the axis direction using the property editor. Unfortunately, it reversed both the axis direction *and* the dendrogram itself, so the final effect is just as wrong as it was before. – kc2001 May 13 '11 at 03:14
0

I needed something similar. I don't know if it is new to Matlab R2021b, but there is now a plot(tree) function which will draw the tree on a regular Matlab figure. After plotting, I identify the largest X value and update the XTickLabels.

B = [1 2 ; 3 4];
tree = phytree(B);
h = plot(tree);
ax = h.axes;

xdata = get(findobj(h.axes,'Type','Line'),'XData');
maxdist = max([xdata{:}]);
ax.XTickLabel = num2str(maxdist - str2double(ax.XTickLabel));

Phylogenetic tree with reversed Xtick labels