❝1、《KS科研分享与服务》公众号有QQ交流群,但是进入门槛是20元,请考虑清楚。群里有推文的注释代码和示例数据,付费内容半价,还可以与大家交流。 2、单细胞转录组全流程代码需收费,收费代码包含公众号付费内容,也有很多新增加的内容。需进群或者需单细胞代码的小伙伴请添加作者微信了解,请备注目的,除此之外请勿添加,谢谢! 3、付费文章集合有打包价!付费作图+单细胞全套也有打包价哦! 详情请联系作者: ❞ 之前我们分享过网络图(graph包:圆状网络图的绘制|互作网络图|基因通路网络图,新方法---大型网络图绘制---ggraph包),其实原理都是基于ggraph包的ggraph函数。最近在NAR上看到一篇文章: 我们借此机会,通过ggraph作图解析相关参数。详细注释代码和参数已上传QQ群文件!我做的图如下,有一点问题,但不影响我们对这个函数的解析。加载R包和节点数据,可以是STRING分析得到的网络文件,也可以是miRNA对应靶基因文件,再或者可以是转录因子对应的调控文件等!
setwd("D:/KS项目/公众号文章/网络节点图") df <- read.csv("network.csv", header = T) colnames(df) <- c("ID", "path", "gene", "Pval") library(ggraph) library(tidygraph)
paths <- c("Node1", "Node2", "Node3") nodelist <- list() for (i in 1:length(paths)){ node <- subset(df, path == paths[i]) nodes <- data.frame(name = unique(union(node$path, node$gene))) nodes$values <- c(sum(node$Pval), node$Pval) nodelist[[i]] <- nodes }
nodes <- rbind(nodelist[[1]],nodelist[[2]],nodelist[[3]]) nodes$cluster <- c(rep("Node1",1),rep("gene",12), rep("Node2",1),rep("gene",11), rep("Node3",1),rep("gene",10))
edges <- df[c("path","gene","Pval")] edges$class <- edges$path
layout_cir <- tbl_graph(nodes = nodes, edges = edges)
ggraph(layout_cir,layout='linear',circular = TRUE) + geom_node_point(aes(size=values,colour = cluster))+ geom_node_text(aes(x = 1.03 * x, y = 1.03 * y, label=name, color=cluster, angle = -((-node_angle(x, y) + 90) %% 180) + 90), hjust='outward') + geom_edge_arc(aes(colour=class))+ theme_void()+ theme(legend.position = "none")+ scale_colour_manual(values =c('#407972', '#961E28', '#D46724', '#0f8096'))+ scale_edge_colour_manual(values = c('#961E28', '#D46724', '#0f8096'))+ scale_size_continuous(range = c(2,8))+ coord_cartesian(xlim=c(-1.5,1.5),ylim = c(-1.5,1.5)) 这样就完成了,也是美美的。如果觉得我的分享对你有用、有帮助的话,点个赞、分享一下再走呗!!!
|