talgalili / dendextend

Extending R's Dendrogram Functionality
153 stars 29 forks source link

Layout messed up when ggplotting an hanged dendrogram #16

Open theclue opened 9 years ago

theclue commented 9 years ago

I noticed some layout glitches when trying to plot the iris example with the 'hanged' option in ggplot. Here the reproducible example:

dend <- iris[1:30,-5] %>% dist %>% hclust %>% as.dendrogram %>% hang.dendrogram(hang = 0.1) %>%
  set("branches_k_color", k=3) %>% set("branches_lwd", c(1.5,1,1.5)) %>%
  set("branches_lty", c(1,1,3,1,1,2)) %>%
  set("labels_colors") %>% set("labels_cex", c(.9,1.2)) %>% 
  set("nodes_pch", 19) %>% set("nodes_col", c("orange", "black", "plum", NA))
# plot the dend in usual "base" plotting engine:
plot(dend, horiz=TRUE)

# Now let's do it in ggplot2 :)
ggd1 <- as.ggdend(dend)
library(ggplot2)
# the nodes are not implemented yet.
ggplot(ggd1) # reproducing the above plot in ggplot2 :)

and here's the output...it doesn't look very good :)

image

tnx for this wonderful package and have a nice day! gabriele

talgalili commented 9 years ago

Hi gabriele, Thank you for the report and the kind words.

I get a different plot from the one you presented. I did updated the relevant functions in dendextend recently on CRAN. Could you please install the package again, and see if you get the same result?

Cheers, Tal

theclue commented 9 years ago

Uhm...I installed the package today, so I'm sure I have the latest version.

I'll try to reproduce at office, where I have a different environment, and I'll post here the plot.

I'll be back in a couple of hours :) gabriele

jefferis commented 9 years ago

On 10 Nov 2015, at 08:15, Gabriele Baldassarre notifications@github.com wrote:

Uhm...I installed the package today, so I'm sure I have the latest version.

I get the same result as in Gabriele’s original message. Best,

Greg.

sessionInfo() R version 3.2.1 (2015-06-18) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.9.5 (Mavericks)

locale: [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] dendextend_1.1.2 ggplot2_1.0.1

loaded via a namespace (and not attached): [1] Rcpp_0.12.1 digest_0.6.8 MASS_7.3-40 grid_3.2.1 plyr_1.8.3 gtable_0.1.2
[7] magrittr_1.5 scales_0.3.0 stringi_1.0-1 reshape2_1.4.1 whisker_0.3-2 labeling_0.3
[13] proto_0.3-10 tools_3.2.1 stringr_1.0.0 munsell_0.4.2 colorspace_1.2-6

talgalili commented 9 years ago

Thanks Greg, I can't seem to reproduce the problem. I checked it on two computers (both are PC, and I see yours is Mac, maybe the problem relates to that in some way). If you get any warnings or errors - please let me know. For now, I can't reproduce it.