曲线图。所有组合的点阵(在R中) [英] igraph graph.lattice for all combinations (in R)

查看:9
本文介绍了曲线图。所有组合的点阵(在R中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Greetings:使用R的iggraph包,这个图看起来应该非常简单。我正在尝试确定需要传递哪些参数才能获得子模式和超级模式之间的边。在此示例中,表示了5个项目的项目集。

我确信这是通过igraph中的graph.lattice函数解决的,但我还没有弄清楚要传递的参数。请注意,所展示的图表来自数据挖掘:概念和技术(han,Kamber,&Amp;Pei,2011)。

提前感谢您的指导。

推荐答案

我不认为graph.lattice能够创建这种图形。但您可以定义一个新函数:

graph.comb <- function(word) {
  # creates graph objects from character combination in word
  # example graph.comb("abc")

  do_layer <- function(words) {
    do.call( rbind, lapply(words, function(word){
      l_vec <- sapply(seq_len(nchar(word)), function(l) substring(word, l, l))
      w_comb <- apply(combn(l_vec, nchar(word)-1), 2, paste, collapse = "")
      w_df <- expand.grid(from = w_comb, to = word, stringsAsFactors = FALSE)
    }))
  }

  df_edges <- data.frame(from = word, to = NA, stringsAsFactors = FALSE)
  df2 <- df_edges
  while( min(nchar(df_edges$from)) > 0) {
    df2 <- do_layer(df2$from)
    df_edges <- rbind(df_edges, df2)
  }
  df_edges <- df_edges[complete.cases(df_edges), ]
  df_edges <- df_edges[!duplicated(df_edges), ]
  return(graph.data.frame(df_edges ))
}

与任何字符串一起使用:

g1 <- graph.comb("abcd")
plot(g1, layout = layout.sugiyama(g1)$layout )

结果:

这篇关于曲线图。所有组合的点阵(在R中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆