小杜的生信笔记 发表于 2024-6-24 22:29:38

跟着Nature Metabolism学作图 | 柱状堆积图

[![](data/attachment/forum/plugin_zhanmishu_markdown/202406/8a4418fc0a66d6118a82b40cda72285f_1719239365_9651.jpg)](http://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455861080&idx=2&sn=9f96a445ae6e16348db1b0021a149c77&chksm=8cff293bbb88a02db7fcd76679a8bf245f4de6e436d4c2c332b3decab2eb47027e9a9a2b71ba&scene=21#wechat_redirect)**「一边学习,一边总结,一边分享!」**

### 本期教程

![](data/attachment/forum/plugin_zhanmishu_markdown/202406/eb29214290ff3937cb92848cb2ecd433_1719239365_8941.jpg)

**柱状堆积图**

**❝**

**「小杜的生信笔记」,自2021年11月开始做的知识分享,主要内容是「R语言绘图教程」、「转录组上游分析」、****「转录组下游分析」**等内容。凡事在社群同学,可免费获得自2021年11月份至今全部教程,教程配备事例数据和相关代码,我们会持续更新中。

**❞**

### 往期教程部分内容

![](data/attachment/forum/plugin_zhanmishu_markdown/202406/8b75c15109689e6c417fd1cc02a8643d_1719239365_2533.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/2577e3d3a52621e1874ac8d5e501a51e_1719239365_7733.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/032c75d2750d2fcd039fe581a6d10043_1719239365_4994.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/a899b304d23ae4cd8a480c6686f553a6_1719239365_7641.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/00feb3d6de7f9c51daef222c8311d77b_1719239365_1637.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/d998411e85c72efa7f4a16abff62850a_1719239365_5863.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/90973fc22040ba68022553d103f998ff_1719239365_8437.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/40e1e12833f45268a2964f5b65d00e31_1719239365_7120.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/3631a911aca08f5c3d73889e3f7320d1_1719239365_7236.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/fe7f164a31500918757c6dc368cb32a5_1719239365_8984.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/53a84f69ac219187ea88a343b00a6f6f_1719239365_1354.jpg)![](data/attachment/forum/plugin_zhanmishu_markdown/202406/867a64199aeaebde0fd7776d3a0a172c_1719239365_2001.jpg)

### 导入所需的R包

```abap
library(ggplot2)
library(readxl)
library(reshape2)
library(ggraph)
```

### 导入数据及转换

```abap
data <- read_excel("20240508_Inputdata.xlsx",sheet = "Sheet1")
data
```

```plain
data <- melt(data)
#固定`variable`的因子
data$variable <- factor(data$variable,
                        levels = c("Normal", "Adjacent", "Tumor_1", "Tumor_2"))
```

### 绘图

```abap
ggplot(data, aes(x = Tissue, y = value, fill = variable))+
geom_bar(stat = "identity")+
##'@颜色设置
scale_fill_manual(values = c("#bebada", "#80b1d3", "#8dd3c7", "#e5d8bd"))+
theme_bw(base_size = 14)+
theme(
      legend.title = element_blank(),
      axis.text.x = element_text(angle = 45, hjust = 1, color = "black", size = 10), # nolint
      axis.text.y = element_text(color = "black", size = 10),
      axis.title = element_text(color = "black", size = 12)
    )
```

![](data/attachment/forum/plugin_zhanmishu_markdown/202406/6e47d06a1f07c9192a38bfa3ef7da83f_1719239365_1811.jpg)

```abap
ggplot(data, aes(x = Tissue, y = value, fill = variable))+
geom_bar(stat = "identity")+
##'@颜色设置
#scale_fill_manual(values = c("#bebada", "#80b1d3", "#8dd3c7", "#e5d8bd"))+
scale_color_viridis(end = 0.8, discrete = F)+
theme_bw(base_size = 14)+
theme(
      legend.title = element_blank(),
      axis.text.x = element_text(angle = 45, hjust = 1, color = "black", size = 10), # nolint
      axis.text.y = element_text(color = "black", size = 10),
      axis.title = element_text(color = "black", size = 12)
    )
```

![](data/attachment/forum/plugin_zhanmishu_markdown/202406/828d56811523ac54eab349ff2c8c912c_1719239365_5699.jpg)

**若我们的教程对你有所帮助,请**点赞+收藏+转发**,这是对我们最大的支持。**

### 往期部分文章

**「1. 最全WGCNA教程(替换数据即可出全部结果与图形)」**

* (https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455850466&idx=1&sn=6036fc2a19594f7fc38d65271f21e9cc&scene=21#wechat_redirect)
* (https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455850727&idx=1&sn=1156c2bb0b0c9baff02838f5ffce39bf&scene=21#wechat_redirect)
* (https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455850742&idx=1&sn=3d3eeedb3b58e536a83dc38d15725cd4&scene=21#wechat_redirect)
* (https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455854728&idx=5&sn=bc98befb8dd0f0090bdfe69f3ffdb008&scene=21#wechat_redirect)
* (https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455856103&idx=1&sn=774f8a084d21f757266f35c501c7155d&scene=21#wechat_redirect)

---

**「2. 精美图形绘制教程」**

* [精美图形绘制教程](https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzAwODY5NDU0MA==&action=getalbum&album_id=2614156000866385923&scene=173&from_msgid=2455848496&from_itemidx=1&count=3&nolastread=1#wechat_redirect)

**「3. 转录组分析教程」**

* **「**[转录组上游分析教程[零基础]](https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzAwODY5NDU0MA==&action=getalbum&album_id=2870608342451224581&scene=126&uin=&key=&devicetype=Windows+10+x64&version=63090719&lang=zh_CN&ascene=0)**」**
* **「**[一个转录组上游分析流程 | Hisat2-Stringtie](https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455857417&idx=1&sn=653f3bdb0af386c22a128732ec8a01a4&scene=21#wechat_redirect)**」**

**「4. 转录组下游分析」**

* [批量做差异分析及图形绘制 | 基于DESeq2差异分析](https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455860684&idx=1&sn=7be489c453cca737ad1092c6e4499827&scene=21#wechat_redirect)
* (https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455859512&idx=1&sn=bac01a018f8b58afc7e2b3484f476bf4&scene=21#wechat_redirect)
* [单基因GSEA富集分析](https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455859147&idx=1&sn=b022d80868e4b8014f64d443c82d1668&scene=21#wechat_redirect)
* [全基因集GSEA富集分析](https://mp.weixin.qq.com/s?__biz=MzAwODY5NDU0MA==&mid=2455860201&idx=1&sn=dd65c5b967123a876a6f5a38d4723ca6&scene=21#wechat_redirect)

**「小杜的生信筆記」** **,主要发表或收录生物信息学教程,以及基于R分析和可视化(包括数据分析,图形绘制等);分享感兴趣的文献和学习资料!!**
页: [1]
查看完整版本: 跟着Nature Metabolism学作图 | 柱状堆积图