Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to label nodes in dendrograms #419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/dendrogram.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function treepositions(hc::Hclust, useheight::Bool, orientation=:vertical)
function treepositions(hc::Hclust, useheight::Bool, orientation)

order = StatsBase.indexmap(hc.order)
nodepos = Dict(-i => (float(order[i]), 0.0) for i in hc.order)
Expand All @@ -24,8 +24,9 @@ function treepositions(hc::Hclust, useheight::Bool, orientation=:vertical)
end
end

@recipe function f(hc::Hclust; useheight=true, orientation=:vertical )
@recipe function f(hc::Hclust; useheight=true, orientation=:vertical, leaflabel=string)
typeof(useheight) <: Bool || error("'useheight' argument must be true or false")
nodeslabels = map(leaflabel, hc.order)

legend --> false
linecolor --> :black
Expand All @@ -34,7 +35,7 @@ end
yforeground_color_axis --> :white
ygrid --> false
ylims --> (0.5, length(hc.order) + 0.5)
yticks --> (1:nnodes(hc), string.(1:nnodes(hc))[hc.order])
yticks --> (1:nnodes(hc), nodeslabels)
if useheight
hs=sum(hc.heights)
xlims --> (0, hs+hs*0.01)
Expand All @@ -46,7 +47,7 @@ end
xforeground_color_axis --> :white
xgrid --> false
xlims --> (0.5, length(hc.order) + 0.5)
xticks --> (1:nnodes(hc), string.(1:nnodes(hc))[hc.order])
xticks --> (1:nnodes(hc), nodeslabels)
ylims --> (0, Inf)
yshowaxis --> useheight
end
Expand Down