【问题标题】:how to color scale a continuous variable using cscale and viridis palette for igraph plot?如何使用 cscale 和 viridis 调色板为 igraph 绘图对连续变量进行颜色缩放?
【发布时间】:2020-10-25 18:16:32
【问题描述】:

我正在 igraph(在 R 中)中绘制一个生物传输网络,我想在基于边缘属性(在我的例子中是一个称为“宽度”的连续变量)的颜色渐变中显示边缘。我不喜欢在以下获得的默认调色板:

plot(graph, edge.color=E(graph)$width)

查看 igraph 绘图帮助,我找到了一种使用 scales 包中的 cscale 更改此调色板的方法:

plot(graph,
edge.color=cscale(E(graph)$width,palette = seq_gradient_pal(low = "yellow",high = "red")))

效果很好,可能会坚持下去。但是我想知道我是否可以使用 viridis 或 colorbrewer 调色板。我还没有弄清楚该怎么做。主要问题是我无法为所有边缘分配颜色编码。例如,如果我这样做:

plot(graph,
 edge.color=cscale(E(graph)$width,palette = viridis_pal())

我收到此警告:

In seq.default(begin, end, length.out = n) :
  first element used of 'length.out' argument

确实第一种颜色应用于所有边缘

如果我尝试指定所有边的长度:

plot(graph,
 edge.color=cscale(E(graph)$width,palette = viridis_pal()(ecount(graph))

我收到此错误消息:

Error in palette(x) : invalid argument type)

有什么想法吗?

【问题讨论】:

标签: r igraph


【解决方案1】:

我有一个类似的问题 --- 我想使用 viridis 调色板为边缘着色 --- 我用 SymbolixAU's colourvalues 解决了这个问题。

library(igraph)
library(viridis)
library(colourvalues)


# read in data frame with pairwise distances, 
# convert to lower triangular matrix, and 
# stash the column names for later use.  Then,

g <- graph_from_adjacency_matrix(m,mode="lower",weighted=TRUE,add.colnames=TRUE)
V(g)$name <- colnames(m)
E(g)$color <- colour_values(E(g)$weight,palette = "viridis")
plot(g, vertex.label=V(g)$name,edge.width = E(g)$weight/10, edge.label=E(g)$weight,edge.color=E(g)$color)

最诚挚的感谢,SymbolixAU!

【讨论】:

  • 太棒了!!感谢发帖!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-06
  • 2011-08-19
  • 2014-11-06
  • 2021-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多