r - 如何更改ggnetwork中geom_node的颜色?
问题描述
我正在尝试进行疾病模拟,我希望受感染的节点(is_infected>0)为红色,未感染的(is_infected=0)节点颜色为青色。
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()
解决方案
这可能很有用,但在缺乏共享数据的情况下未经测试:
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"))
推荐阅读
- flutter - 如何在不更改默认图标的情况下执行 appbar 后退按钮单击操作
- php - 使用 add_filter 将参数传递给函数
- python - 有没有办法将 tkinter 画布嵌入 HTML 网页?
- jpa - JPA:如何将一些实体映射到另一个数据库实例的不同模式?
- rabbitmq - 带有`send_task`的芹菜扇出信号
- linux - curl -SL 有什么作用?
- mysql - 如何统一字段?
- django - 无法修复 django.core.exceptions.AppRegistryNotReady:应用尚未加载
- php - 没有重定向的自定义 404 页面 htaccess
- spring-boot - InvalidQueryException:未配置的表