交互式和弦图查看ggplot全部的图层和参数设置-常用长记
写在前面
在弦图绘制方面,除了基础包之外还有ggplot版本的ggraph,这里其实还有交互的和弦图的绘制方法,例如,edgebundleR包,成图效果如下所示:
require(igraph)
ws_graph = watts.strogatz.game(1, 50, 4, 0.05)
edgebundle(ws_graph,tension = 0.1,fontsize = 20)
之前google到一份图,ggplot的图层和设置参数,认为十分完正,可视化出来也是很有创意,这里给大家链接和图片:点击原文但是遗憾的是没有数据,我们没办法进行重现,这几天我自己整理了图层,并重现这张图片,顺便学习这种交互式的和弦图绘制方法,在网络中尤其有用。
ggplot图层和参数绘制
widgetframe包和edgebundleR都在cran中,常规安装即可:
library(igraph)
# install.packages("widgetframe")
library(edgebundleR)
library(dplyr)
library(purrr)
suppressPackageStartupMessages(library(widgetframe))
parameters <- readLines("./geom_aes.csv")
head(parameters)
split_up <- function(x){
params <- unlist(strsplit(x, ","))
return(data.frame("from" = params[1], "to" = params[2:length(params)]))
}
relationship <- map_df(parameters, split_up)
head(relationship)
relationship$to = as.character(relationship$to)
knitr::kable(head(sort(table(relationship$to), decreasing = T), n = 10))
knitr::kable(head(sort(table(relationship$from), decreasing = T), n = 10))
frameWidget(edgebundle(graph_from_data_frame(relationship), tension = 0.45, cutoff = 0.1, width = NULL, fontsize = 14,
padding = 110, nodesize = c(5, 20), directed = FALSE), height = "600")