Skip to content

problem in geom_conn_bundle aesthetics mappings #122

@m-hoseini

Description

@m-hoseini

Hi,
It seems that geom_conn_bundle aesthetics are not correctly mapped to the edges. A simple example (base on https://www.r-graph-gallery.com/310-custom-hierarchical-edge-bundling/): There are 12 nodes (like a clock), each connected with its opposite node (1 to 7, 2 to 8, 3 to 9, etc.) with the value 10 and with the other nodes with the value 1. Assigning the value to aesthetics is only applied to some of the opposite connections and not all and is applied to some non-opposite connections.

# Libraries
library(ggraph)
library(igraph)
library(tidyverse)

# create a data frame giving the hierarchical structure of your individuals
d1=data.frame(from="origin", to=paste("group", seq(1,2), sep=""))
d2=data.frame(from=rep(d1$to, each=6), to=paste("subgroup", seq(1,12), sep="_"))
hierarchy=rbind(d1, d2)

# create a dataframe with connection between leaves (individuals)
all_leaves=paste("subgroup", seq(1,12), sep="_")
connect=data.frame(from=rep(all_leaves, each=12) , to=rep(all_leaves,12), value=1)
connect$value[c(seq(7,72,13),seq(73,144,13))]=10
connect=subset(connect,from!=to)

# create a vertices data.frame. One line per object of our hierarchy
vertices = data.frame(
  name = unique(c(as.character(hierarchy$from), as.character(hierarchy$to)))) 

# Create a graph object
mygraph <- graph_from_data_frame( hierarchy, vertices=vertices )

# The connection object must refer to the ids of the leaves:
from = match( connect$from, vertices$name)
to = match( connect$to, vertices$name)

# Basic graph
p=ggraph(mygraph, layout = 'dendrogram', circular = TRUE) + 
  geom_node_point(aes(filter = leaf, x = x*1.05, y=y*1.05)) +
  geom_node_text(aes(x = x*1.1, y=y*1.1, filter = leaf, label=name))+
  theme_void()

p +  geom_conn_bundle(data = get_con(from = from, to = to, value=connect$value), 
                      tension=0.3, colour="skyblue",
                      aes(width=value, alpha=value)) 

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions