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

Change segment.color based on edge attribute in ggnetworkmap() #446

Open
evhersh opened this issue Aug 30, 2022 · 1 comment
Open

Change segment.color based on edge attribute in ggnetworkmap() #446

evhersh opened this issue Aug 30, 2022 · 1 comment

Comments

@evhersh
Copy link

evhersh commented Aug 30, 2022

Is it possible to change the segment colors based on edge attributes in my network object in ggnetworkmap()? I see options to do that for the vertices, but there does not appear to be any options for edges. I also tried creating a vector of colors to feed into the segment.color argument, but it returns an error saying "Aesthetics must be either length 1 or the same as the data (702): colour" despite the fact that I only have 69 edges (not 702).

I tried to make an example here:

# load dataset
data(twitter_spambots)
# create colors to set as edge attributes
cols1 <- brewer.pal(n = 10, name = "Set1")
twitter_spambots %e% "weight" <- sample(cols1, replace = TRUE)

# create a world map
world <- fortify(maps::map("world", plot = FALSE, fill = TRUE))
world <- ggplot(world, aes(x = long, y = lat)) +
  geom_polygon(aes(group = group), color = "grey65",
               fill = "#f9f9f9", size = 0.2)

# view global structure
ggnetworkmap(world, twitter_spambots, segment.color=weight) # does not recognize edge attribute name

#alternately try creating color vector
edge.cols1 <- get.edge.value(twitter_spambots, "weight")

#still doesn't work
ggnetworkmap(world, twitter_spambots, segment.color=edge.cols1)
@bananabenana
Copy link

+1 for this feature! Would be super helpful

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

No branches or pull requests

2 participants