Search code examples
rpropertieslabelvertexigraph

Add textual property to nodes in igraph with R


I have some issue while adding properties of nodes in igraph working with R. I made a text list named journal.txt and I want to give the nodes of my graph a property. With other textual or numeric lists, I had absolutely no issues, but with this one I have.

with this I read the txt file, read just the first column, although there is just one, read as character, although i tried also without and it doesn't work

journalList = read.csv("c:/temp/biblioCoupling/journals.txt", header=FALSE)
journalLR = (journalList[1:303,1]) 
journalLR = as.character(journalLR) 
V(g)$journalName = journalLR

then when I save the file,

write.graph(gr,"filename.gml",format=c("gml"), creator="Claudio Biscaro")

I see all other properties I added to nodes, but not this one!!!

could it be because some entry in journalLR is more than 15 character long? I have absolutely no idea why I can't do that


Solution

  • Your code is not reproducible, it is impossible to tell for sure, but I guess that V(g)$journalName is a complex attribute, i.e. it is not a vector of values, but a list of values.

    To check, you can do str(g) and then look at the code letter after the journalName attribute. If it is x, then it is complex, if it is c, then it is character.

    If this is the problem and you don't really need a list, then the workaround is to do

    g <- remove.vertex.attribute(g, "journalName")
    V(g)$journalName <- journalName