本节来介绍一个R包ggflowchart其主要是用来绘制流程图,以后看来可以告别各种思维导图软件了,代码过程非常的简洁明了,更多内容请参考作者官方文档。
https://nrennie.github.io/ggflowchart/articles/decision-tree-example.html
# install.packages("ggflowchart")
library(tidyverse)
library(ggflowchart)data <- tibble::tibble(from = c("A", "A", "A", "B", "C", "F"),
to = c("B", "C", "D", "E", "F", "G"))ggflowchart(data)
ggflowchart(data,
colour = "black", # 边框颜色
text_colour = "red", # 字体颜色
arrow_colour = "blue", # 箭头颜色
family = "serif",
x_nudge = 0.25)
node_data <- tibble::tibble(
name = c("A", "B", "C", "D", "E", "F", "G"),
type = c("Type 1", "Type 1", "Type 1", "Type 1",
"Type 2", "Type 2", "Type 2")
)
ggflowchart(data, node_data, fill = type)
goldilocks <- tibble::tibble(
from = c(
"Goldilocks",
"Porridge", "Porridge", "Porridge",
"Just right",
"Chairs", "Chairs", "Chairs",
"Just right2",
"Beds", "Beds", "Beds",
"Just right3"
),
to = c(
"Porridge",
"Too cold", "Too hot", "Just right",
"Chairs",
"Still too big", "Too big", "Just right2",
"Beds",
"Too soft", "Too hard", "Just right3",
"Bears!"
)
)
node_data <- tibble::tibble(name = c(
"Goldilocks", "Porridge", "Just right", "Chairs",
"Just right2", "Beds", "Just right3", "Too cold",
"Too hot", "Still too big", "Too big", "Too soft",
"Too hard", "Bears!"
)) %>%
dplyr::mutate(label = gsub("\\d+$", "", name))ggflowchart(goldilocks, node_data)
node_data <- node_data %>%
dplyr::mutate(
type = c("Character", "Question", "Answer",
"Question", "Answer", "Question",
"Answer", "Answer", "Answer",
"Answer", "Answer", "Answer",
"Answer", "Character")
)
ggflowchart(goldilocks, node_data, fill = type)
library(rcartocolor)
ggflowchart(goldilocks,
node_data,
fill = type,
colour = "#585c45",
text_colour = "#585c45",
arrow_colour = "#585c45"
) +
scale_x_reverse() +
scale_fill_carto_d(palette = "Antique") +
labs(title = "The Goldilocks Decision Tree") +
theme(
legend.position = "none",
plot.background = element_rect(
colour = "#f2e4c1",
fill = "#f2e4c1"
),
plot.title = element_text(
size = 20,
hjust = 0.5,
face = "bold",
colour = "#585c45"
)
)
有需要学习个性化数据可视化的朋友,欢迎到小编的淘宝店铺 R语言数据分析指南购买2023年度会员
初始价格99元,内容主要包括各种高分论文的图表分析复现以及一些个性化图表的绘制均包含数据+代码;按照往年数据小编年产出约在150+以上
购买后微信发小编订单截图即邀请进新的会员交流群,小编的文档为按年售卖,只包含当年度的除系列课程外的文档,有需要往年文档的朋友也可下单购买,需要了解更多信息的朋友欢迎交流咨询。






本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。