I am trying to assign the same color gradient to both, edges and vertices on igraph using R. The gradient should color from low to high counts in the V(data_graph)$Counts portion.
Some reproducible data:
library(igraph) 
data <- data.frame(Country = c("Africa", "Argentina", "Bolivia", "Chile", "France", "Guam", "Poland", "Greenland", "Switzerland", "UK", "US"), 
               Counts = c(2,2,8,1,5,3,3,15, 15,30,35), 
               Pillar = c(rep("SoS", 4), rep("CNES", 4), rep("STE", 3)))
data_center <- setNames(data.frame("c", 1, "Sos"), names(data))
data_vtx <- rbind(data_center, data)
data_rel <- data.frame(from = head(data_vtx$Country, 1), 
                    to = data_vtx$Country[2:12])
which produces the following graph:
data_graph <- graph_from_data_frame(data_rel,  directed = FALSE, data_vtx)
plot(data_graph, 
 layout = layout.fruchterman.reingold(data_graph),
 vertex.size = round(V(data_graph)$Counts/1.5, 2), 
 vertex.label.color = "black",
 edge.curved = 0.3)
However, next I would like to apply the same color gradient to both, the vertex and the edges based on the V(data_graph)$Counts. What I need is something similar to the scale_color_gradient2 command from ggplot2.
Example:
scale_color_gradient2(low = “blue”, mid = “yellow”, high = “red”, midpoint = mean(V(data_graph)$Counts))
The closest I have found is the following post: How can I assign color range to edges in igraph plot in R based on edge attributes? This post was very informative on making a color gradient in igraph, but each edge there has it's own color. Because some of the V(data_graph)$Counts are the same, they should be colored the same in the color gradient.
Any help will be greatly appreciated!
