R/glasso+igraph+networkD3에서 변수간의 관계를 인터랙티브하게 시각화②

모처럼 왜 Species마다 시각화.
library(dplyr)
library(glasso)
library(igraph)
library(networkD3)

f <- function(x){
  x <- iris %>% filter(Species == x) %>% select(-Species)
  print(dim(x))
  s <- x %>% scale() %>% cov()
  fit <- glasso(s = s, rho = 0.5)
  a <- ifelse(fit$wi != 0, TRUE, FALSE)
  diag(a) <- 0
  colnames(a) <- colnames(x)
  rownames(a) <- colnames(x)
  g <- graph_from_adjacency_matrix(a, mode = "undirected")
  networkData <- as.data.frame(as_edgelist(g))
  return(simpleNetwork(Data = networkData, fontSize = 14, nodeColour = "#006e54", opacity = 1))
}
f("setosa")
f("versicolor")
f("virginica")

Species == "setosa"





Species == "versicolor"





Species == "vriginica"



좋은 웹페이지 즐겨찾기