thomasp85 / ggraph

Grammar of Graph Graphics
https://ggraph.data-imaginist.com
Other
1.07k stars 115 forks source link

Layout dendrogram can't specify edge color #177

Closed qinzhu closed 5 years ago

qinzhu commented 5 years ago

RT. Please see attached code and output for details:

> ggraph(cur_gp %>% activate(nodes), layout = 'dendrogram', circular = T) +
+     geom_edge_link(aes_string(color = "time"))
Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
Error: All columns in a tibble must be 1d or 2d objects:
* Column `edge_colour` is function
Call `rlang::last_error()` to see a backtrace
> ggraph(cur_gp %>% activate(nodes), layout = 'dendrogram', circular = T) +
+     geom_edge_elbow(aes_string(color = "time"))
Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
Don't know how to automatically pick scale for object of type standardGeneric. Defaulting to continuous.
Error: All columns in a tibble must be 1d or 2d objects:
* Column `edge_colour` is function
* Column `direction` is standardGeneric
Call `rlang::last_error()` to see a backtrace

Another related issue is I wonder if it's possible to specify edge length in dendrogram. Thanks!

thomasp85 commented 5 years ago

You should pass time unquoted in aes() as per ggplot2 conventions

dmontecino commented 4 years ago

Hi @thomasp85!

hey, I was wondering how can I manually specify the color of the edges using geom_edge_elbow2. I am building a dendogram that has 5 main arms. I would like to have colors per arm but also different tones within arm.

I built a color variable in the edges data that has the color names I would like the edges to be. But I get the following problem:

"Error: Discrete value supplied to continuous scale"

This is what I am doing:

colors.for.dend=c("#7F00FF","#CC0000", "#00CC00", "#0080FF", "#404040", "white", rep("#FF3333", 5), rep("white", 3), rep("#B266FF", 1), rep("#FF6666",6), rep("#66FF66", 2), rep("#66B2FF", 2), "#606060", rep("#E5CCFF", 24), rep("#FFCCCC", 57-24), rep("#CCFFCC",66-57), rep("#CCE5FF", 89-66), rep("#E0E0E0",4), rep("#CC99FF", 5), rep("#FF9999", 14), rep("#99FF99",5), rep("#99CCFF", 40-24), rep("#C0C0C0",3))

dat.graph.2[[1]]$color=colors.for.dend

names(dat.graph.2) = c("edges", "vertices")

graph <- tbl_graph(dat.graph.2$vertices, dat.graph.2$edges)

geom_edge_elbow2(aes(edge_width= size*0.1, colour=color), linejoin = "round", lineend = "butt")

Hopefully you can help and thank you very much for the packages man...