Closed ixxmu closed 1 year ago
❝最近看到一个非常好的案例来分享一下,使用igraph,ggraph等R包来自定义绘制代谢通路pathway,原文文档链接见下方,数据可自行去官网下载。代码过程很是简洁,当然难点也许在于构建边文件与点文件。这需要各位观众老爷细细品味
❞
❝https://github.com/cxli233/ggpathway
❞
❝❞
有需要学习数据可视化的朋友欢迎加入小编2022年度VIP群
,目前群内已经上传公众号文档「数据+代码约270篇」,VIP交流群(1)已经500人满员
,随着内容不断增多,为了更好的创做内容现在进群需「付费149元」 年底临近「从即日起至12月底无需转发文档到朋友圈积赞,可直接已129元的价格入群」
❝最近有部分观众老爷找小编做个性化绘图,为了给观众老爷提供更加优质的服务;小编开通了 「淘宝店铺(R语言数据分析指南)」 ,有特殊绘图需求的欢迎关注咨询(「由于小编时间精力有限有需求的请及时下单」)
❞
library(tidyverse)
library(igraph)
library(ggraph)
library(readxl)
library(viridis)
library(RColorBrewer)
library(rcartocolor)
example1_edge_table <- tribble(
~from, ~to, ~label,
"Glc6P", "6P-gluconolactone", "Glc6PHD",
"6P-gluconolactone", "6P-glucoconate", "6P-gluconolactonase",
"6P-glucoconate", "Ru5P", "6P-gluconateDH"
)
# 构建点数据
example1_nodes_table <- tribble(
~name, ~x, ~y,
"Glc6P", 1, 0,
"6P-gluconolactone", 2, 0,
"6P-glucoconate", 3, 0,
"Ru5P", 4, 0
)
example1_network <- graph_from_data_frame(
d = example1_edge_table,
vertices = example1_nodes_table,
directed = T
)
ggraph(example1_network, layout = "manual",
x = x, y = y) +
geom_node_text(aes(label = name), hjust = 0.5) +
geom_edge_link(aes(label = example1_edge_table$label),
angle_calc = 'along',
label_dodge = unit(2, 'lines'),
arrow = arrow(length = unit(0.5, 'lines')),
start_cap = circle(4, 'lines'),
end_cap = circle(4, 'lines')) +
theme_void()
导入数据
example2_edges <- read_excel("OPPP_edges.xlsx")
example2_nodes <- read_excel("OPPP_nodes.xlsx")
example2_nodes <- example2_nodes %>%
mutate(label = str_remove(name, "_\\d"))
example2_network <- graph_from_data_frame(
d = example2_edges,
vertices = example2_nodes,
directed = T)
ggraph(example2_network, layout = "kk") +
geom_node_point(size = 3, aes(fill = as.factor(carbons)),
alpha = 0.8, shape = 21, color = "grey20") +
geom_node_text(aes(label = label), hjust = 0.5, repel = T) +
geom_edge_link(label_dodge = unit(2, 'lines'),
arrow = arrow(length = unit(0.4, 'lines')),
start_cap = circle(1, 'lines'),
end_cap = circle(2, 'lines')) +
scale_fill_manual(values = carto_pal(7, "Vivid")) +
labs(fill = "Carbons") +
theme_void()
导入数据
example3_edges <- read_excel("TCA_cycle_edges.xlsx")
example3_nodes <- read_excel("TCA_cycle_nodes.xlsx")
example3_nodes <- example3_nodes %>%
mutate(label = str_remove(name, "_\\d"))
example3_network <- graph_from_data_frame(
d = example3_edges,
vertices = example3_nodes,
directed = T)
ggraph(example3_network, layout = "manual",
x = x, y = y) +
geom_node_point(size = 3, aes(fill = as.factor(carbons)),
alpha = 0.8, shape = 21, color = "black") +
geom_edge_link(arrow = arrow(length = unit(0.4, 'lines')),
start_cap = circle(0.5, 'lines'),
end_cap = circle(0.5, 'lines'),
width = 1.1, alpha = 0.5) +
geom_node_text(aes(label = label), hjust = 0.5, repel = T) +
annotate(geom = "text", label = "TCA Cycle",
x = 0, y = 0, size = 5, fontface = "bold") +
scale_fill_manual(values = carto_pal(7, "Vivid")) +
labs(fill = "Carbons") +
theme_void() +
coord_fixed()
❝好了本节介绍到此结束,整个代码还是非常简洁的,
❞喜欢的观众老爷欢迎分析转发
,更多详细内容可以参看作者官方文档,「当然更推荐大家加入我的VIP交流群」一定让你感受到物超所值,「添加小编微信请备注来意,以便高效处理」,
https://mp.weixin.qq.com/s/7ERRGmixeYnMl79bvdBQJA