gephi/gephi

"Give colors to nodes" plugin can't recognize my color

Closed this issue · 4 comments

Expected Behavior

I‘m using Gephi(v0.10) in M1 MacOS(v14.4.1). After I make a network by R package microeco, I want to attribute different modules to specific colors so that I can make it consistent in different figures.

Based on the plugin "Give colors to nodes" help, I need a column named "color". So I used this R code to attribute different colors.

module_colors <- c("M1" = "#38678E",
                   "M2" = "#7935F6")

other_color <- "#ff6347"

V(t1$res_network)$color <- ifelse(V(t1$res_network)$module %in% names(module_colors), 
                                  module_colors[V(t1$res_network)$module], 
                                  other_color)

Then, I use the following code to save a .gexf file which can be opened in Gephi.

t1$save_network("test.gexf")

According to the data laboratory in Gephi, the modules are attributed to colors successfully as following picture

image

Current Behavior

But when I click the plugin, it said "No String node attribute containing "color" or "colour" could be found".
image

Possible Solution

Steps to Reproduce

  1. Make a network in R and attribute the colors to modules (Just run directly)
library(microeco)
library(magrittr)
library(ggplot2)
theme_set(theme_bw())

data("sample_info_16S") # 分类表
data("otu_table_16S") # OTU丰度表
data("taxonomy_table_16S") # 物种注释表

dataset <- microtable$new(sample_table = sample_info_16S,
                          otu_table = otu_table_16S, 
                          tax_table = taxonomy_table_16S)
dataset
dataset$tax_table %<>% subset(Kingdom == "k__Bacteria")
dataset$filter_pollution(taxa = c("mitochondria", "chloroplast"))
dataset$tidy_dataset()

## 当OTU数目比较多时候,使用R包WGCNA提代R中基础函数计算相关性
# 加载WGCNA包
t1 <- trans_network$new(dataset = dataset, 
                        cal_cor = "WGCNA", # 使用WGCNA包计算相关性
                        taxa_level = "OTU", # 选择分类水平,可选OTU, Genus, Family, Order, Class, Phylum, Kingdom
                        filter_thres = 0.001, # 相对丰度过滤阈值
                        cor_method = "spearman") # 相关性计算方法
# 构建网络,需要igraph包
t1$cal_network(p_thres = 0.05, 
               COR_cut = 0.6,
               add_taxa_name = "Kingdom",
               delete_unlinked_nodes = TRUE,
               COR_optimization = FALSE) # use random matrix theory (RMT) based method to determine the correlation coefficient
# 返回t1$res_network
t1$cal_module(
  method = "cluster_fast_greedy",
  module_name_prefix = "M")
# 定义模块颜色映射
module_colors <- c("M1" = "#38678E",
                   "M2" = "#7935F6"
                   # 继续添加其他模块及其颜色映射
)

# 定义其他模块的颜色
other_color <- "#ff6347"

# 将颜色信息添加到igraph对象中
V(t1$res_network)$color <- ifelse(V(t1$res_network)$module %in% names(module_colors), 
                                  module_colors[V(t1$res_network)$module], 
                                  other_color)
t1$save_network("test.gexf")
  1. Open "test.gexf" in Gephi and you will get this error.

Context

Attributing different modules to specific colors so that I can make it consistent in different figures.

Your Environment

  • Version used: Gephi 0.10.1
  • Operating System: M1 MacOS(v14.4.1)

Can you please post the gexf file directly here? Thank you.

Sure, thanks for your reply. It doesn't support uploading gexf, so I use .zip.
test.gexf.zip

Ok so to make it work:

In the Data Laboratory,

  • create a column named "colour" and choose String as a type of attribute
  • use the button "Copy data to other column" at the bottom of the Data Lab to copy the values of your original column "color" to the new "colour" column

Now, clicking the button "Give color to your nodes" will work.

Thanks very much! This helps a lot!
So I think the problem is the "color" column is not a String type.