0

I'm trying to change the colors of the edges. Currently the graph displays as follows

graph

While the edges are colored according to the graph property "Polarität" (polarity) , i'd like to switch it up from the default ggplot red and blue color scheme. I'm stumped on how to do this.

Thanks in Advance

ggraph <- ggraph(cog_tidy, layout = 'nicely',) + 
theme_graph()+
  scale_colour_brewer(palette = "Dark2") +
  geom_edge_link2(
    aes(end_cap = circle(6, "pt"), edge_color = Polarität ,width=Gewichtung),
    arrow = arrow(
      angle = 10,
      length = unit(0.1, "inches"),
      ends = "last",
      type = "closed"
    )
  )+ 
  geom_node_point( aes(size = Gradzentralität  ,color = Kategorie), show.legend = TRUE) +
  geom_node_text(aes(label = label), repel=TRUE, position = "identity", size=2) +
  scale_edge_width(range = c(0.1, 1)) 
Adam Quek
  • 6,973
  • 1
  • 17
  • 23
mlt
  • 1
  • 1

1 Answers1

0

You could set the color used for the edges via the scale_edge_color_xxx family of functions. See https://ggraph.data-imaginist.com/reference/index.html#section-scales.

Adapting the default example from ?geom_edge_link2 and scale_edge_color_manual you could assign specific colors like so:

library(ggraph, warn = FALSE)
#> Loading required package: ggplot2
library(tidygraph, warn = FALSE)

set.seed(1)

gr <- create_notable('bull') %>%
  mutate(class = sample(letters[1:3], n(), replace = TRUE)) %>%
  activate(edges) %>%
  mutate(class = sample(letters[1:3], n(), replace = TRUE))

ggraph(gr, 'stress') +
  geom_edge_link2(aes(edge_color = node.class)) +
  scale_edge_color_manual(values = c(a = "purple", b = "orange", c = "black"))

stefan
  • 90,330
  • 6
  • 25
  • 51