You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为社交网络图添加viridis配色方案?

解决社交网络图颜色渐变模糊的方案

使用Viridis配色方案

Viridis系列配色专为连续数据设计,能彻底避免中间色发灰的问题,同时兼顾色觉友好性。只需把你代码里的scale_color_gradient(low="steelblue", high="orange")替换为Viridis的连续配色函数即可,还能通过option参数切换不同风格的子配色(可选值包括"magma"、"plasma"、"inferno"、"cividis")。

修改后的完整代码:

G1.v_sub_plot <- ggraph(G1.v_sub, layout = Layout) + 
  geom_edge_link(alpha=0.2) + 
  geom_node_point(aes(colour = average_duration, 
                      size=as.numeric(Bridge_betw),
                      shape=as.factor(community))) +
  scale_size_continuous(range = c(5, 20)) + 
  # 替换为Viridis连续配色
  scale_color_viridis_c(option = "viridis") +  # 可替换为其他option值
  theme_graph(base_family = 'Helvetica') +
  theme(legend.text = element_text(size=22),
        legend.title = element_text(size=22)) +
  labs(color="Average vigilance duration", 
       size="Bridge betweenness", 
       shape="Community") 
# 注:set.seed()应放在生成Layout之前,才能固定网络图布局

其他备选方案

  • RColorBrewer连续配色:如果偏好特定色调的渐变,可使用scale_color_distiller(),比如冷色调的palette = "YlGnBu"或冷暖对比的palette = "RdYlBu",这类配色同样不会出现灰色中间层。
  • 分段渐变增强差异:若想把average_duration划分为区间展示,让数值差异更直观,可使用scale_color_steps(),示例如下:
scale_color_steps(low = "#1f77b4", mid = "#ffbb78", high = "#d62728", midpoint = median(G1.v_sub$average_duration))

内容的提问来源于stack exchange,提问作者Emily McGlinchey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 17:22:09