Hi, I'm getting the following error in iGraph: Error in graph_from_data_frame: Duplicate vertex names

I'm trying to make a network with "graph_from_data_phrame". When i run "anyDuplicated(x, incomparables = FALSE)" I'm getting the following "[1] 0". I dont know how to find or delete the duplicates, nor if they are in the excel that has the relations, or in the excel that has the atributes of the nodes.

Hi, you're more likely to get an answer if you provide a reproducible example of your code.

Hi, thank you for your answer.

I'm working with the following code:

network <- graph_from_data_frame(d=Atributos, directed= FALSE, vertices=Data_Nodos)

Data_Nodos is the dataset with the relations, here's a part of the dataset (it has 119 obs.)

source target importance linea
1 3 1 1
1 2 1 1
1 6 1 1
1 7 1 1
1 8 1 1
1 9 1 1
1 10 1 1
1 11 1 1
1 13 1 1
1 17 1 1
1 25 1 1
1 26 1 1
1 30 1 1
1 37 1 1
1 38 1 1
2 6 1 1
2 25 1 1
3 4 1 1
3 5 1 1
3 7 1 1
3 14 1 1

Atributos is the dataset with the nodes atributes:

ID Name Departamento Tipologia Interes Color Shape
1 Alcaldia de Puerto Triunfo Antioquia Autoridad local Alto #3C6B0A square
2 Ganaderos de Puerto Triunfo Antioquia Comunidad local Alto #3C6B0A star
3 Cornare Antioquia Autoridad ambiental Alto #3C6B0A circle
4 Corantioquia Antioquia Autoridad ambiental Alto #3C6B0A circle

Hello,
I'm sure you shared this image with the best intentions, but perhaps you didnt realise what it implies.
If someone wished to use example data to test code against, they would type it out from your screenshot...

This is very unlikely to happen, and so it reduces the likelihood you will receive the help you desire.
Therefore please see this guide on how to reprex data. Key to this is use of either datapasta, or dput() to share your data as code

Hey, thanks for your reply

I pasted a bit of both data sets and didn't share the screenshot at the end. I wonder if it's of like this.

Thank you again

This is not the recommended way to provide it.

Often times people will go to extra length to help out .., so i wont be suprised if you get help from thus; but i just want to point out you arent doing everything that you could do, to make it easy for people to help you, as has been suggested to you.

1 Like

Data to start with anyway:

Data_Nodos <- data.frame(
  source = c(1L,1L,1L,1L,1L,
             1L,1L,1L,1L,1L,1L,1L,1L,
             1L,1L,2L,2L,3L,3L,3L,3L),
  target = c(3L,2L,6L,7L,8L,
             9L,10L,11L,13L,17L,25L,26L,
             30L,37L,38L,6L,25L,4L,5L,
             7L,14L),
  importance = c(1L,1L,1L,1L,1L,
                 1L,1L,1L,1L,1L,1L,1L,1L,
                 1L,1L,1L,1L,1L,1L,1L,1L),
  linea = c(1L,1L,1L,1L,1L,
            1L,1L,1L,1L,1L,1L,1L,1L,
            1L,1L,1L,1L,1L,1L,1L,1L)
)

Atributos <- data.frame(
  stringsAsFactors = FALSE,
  ID = c(1, 2, 3, 4),
  Name = c("Alcaldia de Puerto Triunfo",
           "Ganaderos de Puerto Triunfo",
           "Cornare",
           "Corantioquia"),
  Departamento = c("Antioquia","Antioquia","Antioquia","Antioquia"),
  Tipologia = c("Autoridad local","Comunidad local",
                "Autoridad ambiental","Autoridad ambiental"),
  Interes = c("Alto", "Alto", "Alto", "Alto"),
  Color = c("#3C6B0A","#3C6B0A","#3C6B0A","#3C6B0A"),
  Shape = c("square", "star", "circle", "circle")
)

library(igraph)
network <- graph_from_data_frame(d=Atributos, directed= FALSE, vertices=Data_Nodos)

library(igraph)
network <- graph_from_data_frame(d=Atributos, directed= FALSE, vertices=Data_Nodos)

Error in graph_from_data_frame(d = Atributos, directed = FALSE, vertices = Data_Nodos) :
Duplicate vertex names

This is the data:

Data_Nodos <-
structure(
list(
source = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
target = c(3,
6, 7, 8, 9, 10, 11, 13, 17, 25),
importance = c(1, 1, 1, 1, 1,
1, 1, 1, 1, 1),
linea = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
),
row.names = c(NA,-10L),
class = c("tbl_df", "tbl", "data.frame")
)

Atributos_strut <-
structure(
list(
ID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
Name = c(
"Alcaldia de Puerto Triunfo",
"Ganaderos de Puerto Triunfo",
"Cornare",
"Corantioquia",
"Ministerio de Ambiente",
"EMISORA MI GENTE PORTEÑA Puerto Triunfo",
"Asociacion Ambientalista Futuro Verde",
"Asociacion de pescadores y medio ambiental de Estación Cocorna",
"Grupo ecologico de Estacion Pita",
"Asociacion Ambientalista Pacha Mama Madre Tierra"
),
Departamento = c(
"Antioquia",
"Antioquia",
"Antioquia",
"Antioquia",
"Antioquia",
"Antioquia",
"Antioquia",
"Antioquia",
"Antioquia",
"Antioquia"
),
Tipologia = c(
"Autoridad local",
"Comunidad local",
"Autoridad ambiental",
"Autoridad ambiental",
"Autoridad ambiental",
"Comunidad local",
"Comunidad local",
"Comunidad local",
"Comunidad local",
"Comunidad local"
),
Interes = c(
"Alto",
"Alto",
"Alto",
"Alto",
"Alto",
"Medio",
"Alto",
"Alto",
"Alto",
"Alto"
),
Color = c(
"#3C6B0A",
"#3C6B0A",
"#3C6B0A",
"#3C6B0A",
"#3C6B0A",
"#dbd402",
"#3C6B0A",
"#3C6B0A",
"#3C6B0A",
"#3C6B0A"
),
Shape = c(
"square",
"star",
"circle",
"circle",
"circle",
"star",
"star",
"star",
"star",
"star"
)
),
row.names = c(NA,-10L),
class = c("tbl_df", "tbl",
"data.frame")
)

The code is the following:
network <- graph_from_data_frame(d=Atributos, directed= FALSE, vertices=Data_Nodos)

I think you swapped the edge list for the vertex list...
also the vertex list doesnt cover all the vertexes listed in the edge list so it will cause an error. to fix that you would need the appropriate data...

library(igraph)
network <- graph_from_data_frame(d=Data_Nodos, directed= FALSE) #, vertices=Atributos)
plot(network)

The above was made from William's reprex

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.