rggplot2data-visualizationggprotoggnetwork

How to change the color of geom_node in ggnetwork?


I am trying to do a disease simulation, where I want the infected node(is_infected>0) to be red and the un-infected(is_infected=0) node color to be cyan.

                results <- results %>% mutate(
                        S = infected == 0,
                        E = 0 < infected & infected < 6,
                        I = infected >= 6 & infected <= 11,
                        R = infected > 11,
                        is_infected = infected > 0
                )
                
                net.layout.by.time <-
                        split(results, f = results$t%in% c(5, 7, 16, 40, 80)) %>%
                        lapply(FUN = right_join,
                               y = net.layout,
                               by = "id") %>%
                        bind_rows
                
                net.layout.by.time <- split(results, f = results$t) %>%
                        lapply(FUN = right_join, y = net.layout, by = "id") %>% 
                        bind_rows
                
                net.layout.by.time %>% 
                        filter(t %in% c(5, 6, 7, 20, 40)) %>%
                        ggplot(aes(xend = xend, yend = yend, x = x, y = y)) + 
                        geom_edges(color = "lightgray") +
                        geom_nodes(aes(color = is_infected)) + 
                        facet_wrap(~ t) + 
                        theme_blank()

My code produces the exact opposite.enter image description here How can I change that?


Solution

  • This can be useful but not tested in lack of shared data:

    library(ggplot2)
    #Code
    net.layout.by.time %>% 
                            filter(t %in% c(5, 6, 7, 20, 40)) %>%
                            ggplot(aes(xend = xend, yend = yend, x = x, y = y)) + 
                            geom_edges(color = "lightgray") +
                            geom_nodes(aes(color = is_infected)) + 
                            facet_wrap(~ t) + 
                            theme_blank()+scale_color_manual(values=c("blue","red"))