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

Segmented node colours #218

Open
kdome opened this issue Nov 8, 2019 · 2 comments
Open

Segmented node colours #218

kdome opened this issue Nov 8, 2019 · 2 comments

Comments

@kdome
Copy link

kdome commented Nov 8, 2019

Is there some way to segment nodes into multiple sections of different colours? I'm imagining something where a node belongs to, say, two categories and can be split into a blue half and a green half. If not, could this be considered for a future release?

@thomasp85
Copy link
Owner

This is not really possible at the moment

@schochastics
Copy link
Contributor

here is a "workaround" that I came up with

library(igraph)
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#> 
#>     union
library(scatterpie)
#> Loading required package: ggplot2
library(ggraph)
set.seed(1439)
# create a random graph with three random attributes
g <- sample_pa(20, 1)
V(g)$A <- abs(rnorm(20, sd = 1))
V(g)$B <- abs(rnorm(20, sd = 2))
V(g)$C <- abs(rnorm(20, sd = 3))

# precompute the layout
xy <- graphlayouts::layout_with_stress(g)
V(g)$x <- xy[, 1]
V(g)$y <- xy[, 2]

ggraph(g, "manual",x=xy[,1],y=xy[,2]) +
    geom_edge_link0() +
    geom_scatterpie(
        aes(x=x,y=y),
        cols = c("A", "B", "C"),
        data = as_data_frame(g, "vertices"),
        colour = NA,
        pie_scale = 2
    ) +
    coord_fixed() +
    theme_graph() +
    theme(legend.position = "bottom")

Created on 2024-01-16 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants