rggplot2sna

Customize color of lines in Social Network Visual in ggplot2


I'm struggling with the following issue. I visualized a big social network and would like to customize the color palette of the edges captured in geom_segmentfor better visibility. For instance, I want to replace my blue scale by a red scale. How can I achieve that in the easiest way possible?

I have the following code which is working fine:

ggplot(nodes_geo) + country_shapes +
  geom_segment(aes(x = x, y = y, xend = xend, yend = yend, alpha = weight, color = weight     # draw edges as arcs
                  ),
               data = edges_for_plot, curvature = 0.33,
               ) +
  scale_size_continuous(guide = FALSE, range = c(0.25, 2)) + # scale for edge widths
  geom_point(aes(x = longitude, y = latitude, size = weight),           # draw nodes
             shape = 21, fill = 'white',
             color = 'black', stroke = 0.5) +
  scale_size_continuous(guide = FALSE, range = c(0.01, 2)) + # scale for node size
  mapcoords + maptheme     

Many thanks in advance!


Solution

  • Thanks to stefan, I used the following code which changed the color from blue to red using scale_color_gradient.

     ggplot(nodes_geo) + country_shapes +
      geom_curve(aes(x = x, y = y, xend = xend, yend = yend, alpha = weight, color = weight     # draw edges as arcs),
      data = edges_for_plot, curvature = 0.33,) +
      scale_color_gradient(low = "red4", high = "red")+ # <-- Customize color
      scale_size_continuous(guide = FALSE, range = c(0.25, 2)) + # scale for edge widths
      geom_point(aes(x = longitude, y = latitude, size = weight),           # draw nodes
                 shape = 21, fill = 'white',
                 color = 'black', stroke = 0.5) +
      scale_size_continuous(guide = FALSE, range = c(0.01, 2)) + # scale for node size
      mapcoords + maptheme