need help with social network empty graph

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 :
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 Graphs suggests 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 think the choice of plotting function is not the reason of the problem.

The OP missed a , after the vertex.size argument. Also, the as.factor parts are not necessary.

The following works.

#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#>     union
eg <- make_empty_graph(n = 1000,
                       directed = FALSE) 
plot(x = eg,
     vertex.color = quakes$depth,
     vertex.size = quakes$mag, 
     vertex.frame.color = "gray",
     vertex.label.color = "black")

Created on 2019-03-12 by the reprex package (v0.2.1)

1 Like

ty it did show me the empty graph but im not sure the nodes set by lat and long variables

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'm not sure I understand you correctly. From what I understand, you're looking for just a scatterplot.

ggplot(data = quakes) +
  geom_point(mapping = aes(x = lat,
                           y = long,
                           colour = depth,
                           size = mag))

Created on 2019-03-13 by the reprex package (v0.2.1)

i need to make an empty graph and the R program said error
the function :
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 ?

I'll suggest you go through the documentation of make_empty_graph. See the excerpt below:


make_empty_graph(n = 0, directed = TRUE) empty_graph(...)

Some more details from here.
#' A graph with no edges
#' @aliases graph.empty
#' @concept Empty graph.
#' @param n Number of vertices.
#' @param directed Whether to create a directed graph.
#' @return An igraph graph.
#' @family determimistic constructors
#' @export
#' @examples
#' make_empty_graph(n = 10)
#' make_empty_graph(n = 5, directed = FALSE)

make_empty_graph <- function(n=0, directed=TRUE) {
  # Argument checks
  n <- as.integer(n)
  directed <- as.logical(directed)
  on.exit( .Call(C_R_igraph_finalizer) )
  # Function call
  res <- .Call(C_R_igraph_empty, n, directed)

You can only supply an integer to this function to the n argument. That's why you're getting an error.

What exactly do you want to plot? And, how does it differ from the scatterplot I provided before?

this is actully no diffrent but at my home work assiment they asked for igraph specifcly

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.