Created
August 23, 2017 13:41
-
-
Save kescobo/799bf484e96a854857cb65f2c5685693 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hclustplot(hc::Hclust, useheight::Bool) | |
o = indexmap(hc.order) | |
n = [x for x in 1:length(o)] | |
pos = treepositions(hc, useheight) | |
xs = [] | |
ys = [] | |
for i in 1: size(hc.merge, 1) | |
x1 = pos[hc.merge[i,1]][1] | |
x2 = pos[hc.merge[i,2]][1] | |
append!(xs, [x1,x1,x2,x2]) | |
y1 = pos[hc.merge[i,1]][2] | |
y2 = pos[hc.merge[i,2]][2] | |
useheight ? h = hc.height[i] : h = 1 | |
newy = maximum([y1,y2]) + h | |
append!(ys, [y1,newy,newy,y2]) | |
end | |
return (reshape(xs, 4, size(hc.merge, 1)), reshape(ys, 4, size(hc.merge, 1))) | |
end | |
function treepositions(hc::Hclust, useheight::Bool) | |
order = indexmap(hc.order) | |
positions = Dict{}() | |
for (k,v) in order | |
positions[-k] = (v, 0) | |
end | |
for i in 1:size(hc.merge,1) | |
xpos = mean([positions[hc.merge[i,1]][1], positions[hc.merge[i,2]][1]]) | |
if hc.merge[i,1] < 0 && hc.merge[i,2] < 0 | |
useheight ? ypos = hc.height[i] : ypos = 1 | |
else | |
useheight ? h = hc.height[i] : h = 1 | |
ypos = maximum([positions[hc.merge[i,1]][2], positions[hc.merge[i,2]][2]]) + h | |
end | |
positions[i] = (xpos, ypos) | |
end | |
return positions | |
end |
indexmap
and mean
are now in StatsBase
and Statistics
packages respectively. So simply add using StatsBase, Statistics
to the start of the recipe. Or simply using StatsKit
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found that the
indexmap
was in DataFrames package. it is easy to make a customized one though.