繁体   English   中英

多图的绘图度分布

[英]Ploting degree distribution for multiple graphs

我有一个包含多个名为的图形的对象: graphs

我想在一张图中绘制这些图的度分布。 我尝试了以下代码,但始终收到以下错误:“'x'是一个列表,但没有组件'x'和'y'”

这是代码:

library(igraph)
getDD  <- function(graph, cumulative = FALSE, ...) {
  if (!is.igraph(graph)) {
    stop("Not a graph object")
  }
  cs <- degree(graph, ...)
  hi <- hist(cs, -1:max(cs), plot = FALSE)$density
  if (!cumulative) {
    res <- hi
  } else {
    res <- rev(cumsum(rev(hi)))
  }
  res
}

generateGraph <- function(x){
return (barabasi.game(100))  
}

# generate 5 graphs
graphs = lapply(1:5, generateGraph)
dDistributions = lapply(graphs, getDD)

plot(dDistributions,  xlab="degree", ylab="cumulative frequency", main="Degree distribution", type="o")

plot()无法处理列表,请在正确设置绘图后逐一遍历列表。 即是这样的:

xlim <- c(0, max(sapply(dDistributions, length)-1))
ylim <- c(0, max(unlist(dDistributions)))

plot(NA, type="n", xlim=xlim, ylim=ylim, xlab="degree", ylab="relative frequency")
sapply(dDistributions, function(x) lines(1:length(x)-1, x, type="l"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM