【问题标题】:Is it possible to scale the size and color of nodes/vertices using ggnetwork based on two variables?是否可以使用基于两个变量的 ggnetwork 来缩放节点/顶点的大小和颜色?
【发布时间】:2020-01-18 04:36:04
【问题描述】:

使用文档中的“血型”示例(Tyner、Briatte 和 Hoffman):

> bt <- as.character( unique( blood$edges$from ) )
> bt_df <- data.frame( type=bt, spin=c(1,2,3,4,5,6,7,8),charm=c(8,7,6,5,4,3,2,1))
Browse[1]> bt_df
  type spin charm
1  AB-    1     8
2  AB+    2     7
3   A-    3     6
4   A+    4     5
5   B-    5     4
6   B+    6     3
7   O-    7     2
8   O+    8     1

是否可以绘制网络图,根据“spin”的值在某个调色板上改变顶点的颜色,并根据“charm”的值改变顶点的大小?

【问题讨论】:

    标签: ggnetwork


    【解决方案1】:

    在文档中找到了答案以及一些试验和错误。关键步骤是“geom_nodes(size=bt_df$spin, color=bt_df$charm)”。

    ggplot( ggnetwork(grph, layout="circle", arrow.gap=0.05),aes(x,y,xend=xend,yend=yend)) +
              geom_edges(color="grey50", arrow=arrow(length=unit(10,"pt"), type="closed")) +
              scale_color_brewer(palette = "Set2") +
              geom_nodes(size=bt_df$spin, color=bt_df$charm) +
              geom_nodetext(aes(label=vertex.names), color="grey80") + 
              theme_blank() +
              coord_fixed( 0.5 )
    

    【讨论】:

      猜你喜欢
      • 2019-11-06
      • 1970-01-01
      • 2019-02-14
      • 2019-11-09
      • 2021-10-11
      • 2019-12-15
      • 1970-01-01
      • 2014-11-07
      • 1970-01-01
      相关资源
      最近更新 更多