MicrobiomeStatPlot |华夫饼图教程Waffle Chart Tutorial

摘要:华夫饼图(waffle chart)分为块状华夫饼图和点状华夫饼图。它是展示总数据的组类别情况的一种有效图表。它是西方的一种由小方格组成的面包,所以这种图表因此得名为华夫饼图。

华夫饼图简介

华夫饼图(waffle chart)分为块状华夫饼图和点状华夫饼图。它是展示总数据的组类别情况的一种有效图表。它是西方的一种由小方格组成的面包,所以这种图表因此得名为华夫饼图。

参考:https://mp.weixin.qq.com/s/9zW4EupcGSNoDH_vy23fPw https://mp.weixin.qq.com/s/0iztINEslPhhIyDXbh_I3w

标签:#

微生物组数据分析 #MicrobiomeStatPlot #R语言可视化 #华夫饼图 #Waffle chartt

作者:

First draft(初稿):Defeng Bai(白德凤);Proofreading(校对):Ma Chuang(马闯) and Jiani Xun(荀佳妮);Text tutorial(文字教程):Defeng Bai(白德凤)

源代码及测试数据链接:

https://github.com/YongxinLiu/MicrobiomeStatPlot/项目中目录 3.Visualization_and_interpretation/WaffleChart

华夫饼图案例

这是来自于范德堡大学医学中心Paula J. Hurley课题组2022年发表于Nature Communications上的一篇论文。论文题目为:Single cell analysis of cribriform prostate cancer reveals cell intrinsic and tumor microenvironmental pathways of aggressive disease.https://doi.org/10.1038/s41467-022-33780-1

图 1c | 患者临床特征。

结果

总体而言,患者患有 2-5 级前列腺癌,即 pT3aN0/X 期或 pT3bN0 期(图 1c 和补充表 1)。

华夫饼图R语言实战

源代码及测试数据链接:

软件包安装

# 基于CRAN安装R包,检测没有则安装p_list = c("ggplot2", "RColorBrewer", "ggforce", "dplyr", "waffle")for(p in p_list){if (!requireNamespace(p)){install.packages(p)} library(p, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)}# 加载R包 Load the packagesuppressWarnings(suppressMessages(library(ggplot2)))suppressWarnings(suppressMessages(library(RColorBrewer)))suppressWarnings(suppressMessages(library(ggforce)))suppressWarnings(suppressMessages(library(dplyr)))suppressWarnings(suppressMessages(library(waffle)))

实战

# 1. Block Waffle Chart 块状华夫饼图# Data Preparationnrows category_counts sorted_counts categories df df$category # Color Palettecolors # Plotblock_waffle_plot geom_tile(color = "grey80", size = 0.1) + scale_fill_manual(values = colors, name = "Category") + coord_fixed(ratio = 1) + scale_x_reverse(expand = c(0, 0)) + scale_y_reverse(expand = c(0, 0)) + labs(title = "Block Waffle Chart of Categories") + theme_minimal(base_size = 14) + theme( panel.grid = element_blank, axis.text = element_blank, axis.title = element_blank, axis.ticks = element_blank, legend.position = "right", legend.title = element_text(size = 12), legend.text = element_text(size = 10) )# Save Plot# ggsave("block_waffle_chart.png", plot = block_waffle_plot, width = 8, height = 8, dpi = 300)ggsave("results/block_waffle_chart.pdf", plot = block_waffle_plot, width = 8, height = 8)#2.Dot Waffle Chart 点状华夫饼图# Data Preparationdf$category # Plotdot_waffle_plot geom_circle(color = "grey40", size = 0.2) + labs(title = "Dot Matrix Distribution by Category") + theme( )# Save Plot#ggsave("dot_waffle_chart.png", plot = dot_waffle_plot, width = 8, height = 8, dpi = 300)ggsave("results/dot_waffle_chart.pdf", plot = dot_waffle_plot, width = 8, height = 8)#3. Stacked Waffle Chart 堆积华夫饼图# Data Preparationunit_size category_data colnames(category_data) category_data category_data$count # Expanded Data for Plottingexpanded_data category_vector expanded_data expanded_data$category # Color Palettecolors # Plotstacked_waffle_plot geom_point(color = "black", shape = 21, size = 4) + scale_fill_manual(values = colors, name = "Category") + coord_fixed(ratio = 1) + labs(title = "Stacked Waffle Chart of Categories", x = "Each Square = 100") + theme_minimal(base_size = 14) + theme( panel.grid = element_blank, axis.text.x = element_text(size = 10), axis.title.x = element_text(size = 12), legend.position = "right" )# Save Plot#ggsave("stacked_waffle_chart.png", plot = stacked_waffle_plot, width = 8, height = 8, dpi = 300)ggsave("results/stacked_waffle_chart.pdf", plot = stacked_waffle_plot, width = 8, height = 8)#4. Faceted Waffle Chart 分面华夫饼图# Data Preparationstorms_summary % filter(year >= 2010) %>% count(year, status)# Plotfaceted_waffle_plot geom_waffle(color = "white", size = 0.3, n_rows = 10, flip = TRUE) + facet_wrap(~ year, nrow = 1, strip.position = "bottom") + scale_fill_brewer(palette = "Paired") + scale_x_discrete + scale_y_continuous(labels = scales::label_number(scale = 1), expand = c(0, 0)) + labs( title = "Faceted Waffle Chart of Storms", subtitle = "Distribution of Storm Statuses (2010 onwards)", x = "Year", y = "Count" ) + theme( legend.position = "right", legend.title = element_text(size = 12), legend.text = element_text(size = 10) )# Save Plot#ggsave("faceted_waffle_chart.png", plot = faceted_waffle_plot, width = 12, height = 6, dpi = 300)ggsave("results/faceted_waffle_chart.pdf", plot = faceted_waffle_plot, width = 12, height = 6)

排版Combo plots

组合多个子图为发表格式

library(cowplot)width = 89height = 59p0 = plot_grid(block_waffle_plot, dot_waffle_plot, stacked_waffle_plot, faceted_waffle_plot, labels = c("A", "B", "C", "D"), ncol = 2)ggsave("results/Waffle_plot.pdf", p0, width = width * 5, height = height * 4, units = "mm")

使用此脚本,请引用下文:

Yong-Xin Liu, Lei Chen, Tengfei Ma, Xiaofang Li, Maosheng Zheng, Xin Zhou, Liang Chen, Xubo Qian, Jiao Xi, Hongye Lu, Huiluo Cao, Xiaoya Ma, Bian Bian, Pengfan Zhang, Jiqiu Wu, Ren-You Gan, Baolei Jia, Linyang Sun, Zhicheng Ju, Yunyun Gao, Tao Wen, Tong Chen. 2023. EasyAmplicon: An easy-to-use, open-source, reproducible, and community-based pipeline for amplicon data analysis in microbiome research. iMeta 2: e83. https://doi.org/10.1002/imt2.83

Copyright 2016-2024 Defeng Bai baidefeng@caas.cn, Chuang Ma 22720765@stu.ahau.edu.cn, Jiani Xun 15231572937@163.com, Yong-Xin Liu liuyongxin@caas.cn

宏基因组推荐

本公众号现全面开放投稿,希望文章作者讲出自己的科研故事,分享论文的精华与亮点。

投稿请联系小编(-genomics)

iMeta高引文章 fastp 复杂热图 ggtree 绘图imageGP 网络iNAP

iMeta网页工具 代谢组MetOrigin 美吉云乳酸化预测DeepKla

iMeta综述 肠菌菌群 植物菌群 口腔菌群 蛋白质结构预测

10000+:菌群分析 宝宝与猫狗 梅毒狂想曲 提DNA发Nature

为鼓励读者交流快速解决科研困难,我们建立了“宏基因组”讨论群,己有国内外6000+ 科研人员加入。请添加主编微信meta-genomics带你入群,务必备注“姓名-单位-研究方向-职称/年级”。高级职称请注明身份,另有海内外微生物PI群供大佬合作交流。技术问题寻求帮助,首先阅读《如何优雅的提问》学习解决问题思路,仍未解决群内讨论,问题不私聊,帮助同行。

来源:微生物组

相关推荐