Updates to better support dendrograms
These changes were made to better support dendrograms, particularly those created with dendextend. It adds support for
fontfaceingeom_text- a rough translation of
hjustandvjustingeom_text -InfandInfingeom_rectguide = "none"
Feedback is very welcome. Below is some sample code.
library(ggplot2)
library(plotly)
library(dendextend)
dend <- iris[1:30,-5] %>% dist %>% hclust %>% as.dendrogram %>%
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))
ggd1 <- as.ggdend(dend)
p = ggplot(ggd1, horiz = TRUE, theme = NULL)
ggplotly(p)
p1 = ggplot(cars) +
geom_point(aes(x = speed, y = dist)) +
geom_rect(xmin = 5, xmax = 10, ymin = -Inf, ymax = Inf)
ggplotly(p1)
p2 = ggplot(cars) +
geom_point(aes(x = speed, y = dist)) +
geom_rect(ymin = 25, ymax = 50, xmin = -Inf, xmax = Inf)
ggplotly(p2)
p3 = ggplot(cars) +
geom_point(aes(x = speed, y = dist)) +
geom_rect(xmin = 5, xmax = 10, ymin = -Inf, ymax = Inf) +
coord_flip()
ggplotly(p3)
p4 = ggplot(cars) +
geom_point(aes(x = speed, y = dist)) +
geom_rect(ymin = 25, ymax = 50, xmin = -Inf, xmax = Inf) +
coord_flip()
ggplotly(p4)
p5 = ggplot(data.frame(x = seq(5, 25, 5), y = 60)) +
geom_point(aes(x = x, y = y)) +
geom_text(x = 5, y = 60, label = "nothing") +
geom_text(x = 10, y = 60, label = "bold", fontface = "bold", hjust = 0, vjust = 0) +
geom_text(x = 15, y = 60, label = "italic", fontface = "italic", hjust = 1, vjust = 1) +
geom_text(x = 20, y = 60, label = "bold italic", fontface = "bold italic", hjust = 0, vjust = 1) +
geom_text(x = 25, y = 60, label = "plain", fontface = "plain", hjust = 1, vjust = 0)
ggplotly(p5)
Sorry for the delay @jrowen, this is looking pretty good...before I merge, would you mind writing a couple simple tests?
Sorry, I too have been away from this for a while. I'll see if I can pull those together shortly. Thanks.
Hi @jrowen Any chance you could get some tests made for this? This would be helpful for heatmaply (since it now has a plot_method="plotly" which could use these features).
Thanks!
I added some checks for geom_text and geom_rect, but I'm not sure how to test the guide = "none" change without introducing a dependency on dendextend (see code below which now works as expected). It also looks like the R:devel build is failing with the R:release build is fine.
library(ggplot2)
library(plotly)
library(dendextend)
dend <- iris[1:30,-5] %>% dist %>% hclust %>% as.dendrogram %>%
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))
ggd1 <- as.ggdend(dend)
p = ggplot(ggd1, horiz = TRUE, theme = NULL)
ggplotly(p)
Don't worry about the build failure @jrowen. I'll have a closer look here next week
Hi Carson, Any chance you can give this a look?
Thanks, Tal
I may get to this next week. #929 will take precedence.
Hi @jrowen, sorry for forgetting about this PR! I thought I was going to have the bandwidth to complete #929, but I'm not sure anymore...I have a couple small questions about this PR, but we should try to get this merged before I submit to CRAN by the end of June
Hey @cpsievert :) Any chance to add this support?