hello , i have problome with my social network , idid get the network but icannot add legends to it please help
heres the instruction :
Each quake is characterized by a couple of integers which determine its position in space (latitude and longitude). Create an empty social network in which each quake is represented by a node (empty_graph() %>% plot.igraph()): • Node size depends on quake intensity (vertex.size = …) • Node color depends on quake depth (vertex.color = …) • Node position depends on latitude and longitude columns (layout = …) Adjust the different parameters to make your map readable (node size, color and latitude/longitude). Add a title and a legend explaining nodes’ color (legend())
my codes :
attach(quakes)
library(igraph)
eg=make_empty_graph(n=1000,directed = F)
plot.igraph(eg,layout=as.matrix(select(quakes,lat,long)),vertex.color=quakes$depth,vertex.size=quakes$mag*5, main="network of quakes")
legend("bottomleft", legend=levels(as.factor(V(eg) , col = coul , bty = "n", pch=20 , pt.cex = 3, cex = 1.5, text.col=coul , horiz = FALSE, inset = c(0.1, 0.1))
what am i doing wrong? without the legends i get the network but with it igot an error
I'm not 100% sure without your data, but the igraph documentation on Drawing Graphssuggests you need to use one of its plotting functions (not base plot()):
The common bits of the three plotting functions plot.igraph , tkplot and rglplot are discussed in this manual page
Edit Actual answer in @Yarnabrina's response, below.
I'm not sure I understand the reason for which the nodes will be set by lat and long of quakes dataset in an empty graph. Can you please explain what you want?
yeha , my data "quakes" has 5 variable lat,long,depth,stations and mag .
lat- latitude of the earthquake
long - longtiude of the earthquke
depth- depth of the eqrthquke at km
stations- number of statinos who report the earthquake
and mag- the magntiude of the earthquke
i need to make an empty graph which the nodes are earthquke by their long and lat for example earthquker 1 has lat 5 and long 7
and i need each node to be coloer by his depth values and sized by his mag values
i need to make an empty graph and the R program said error
the function :
attach(quakes)
library(dplyr)
library(igraph)
empty=make_empty_graph(quakes)
layouts=as.matrix(select(quakes,lat,long))
View(layouts)
plot(empty,vertex.color=quakes$depth,vertex.size=quakes$mag, main="network of quakes")
why is it not working ? and ps how do i add a graph key ?
ty