跟着Nature Methods学画图:R语言ggplot2画气
2021-02-21 本文已影响0人
小明的数据分析笔记本
今天的推文继续重复论文中的原图
在简书 土豆学生信 分享的内容看到这篇论文 简书的链接是 https://www.jianshu.com/p/bbf9cb13b41a
论文是

论文对应的代码是公开的 https://github.com/ajwilk/2020_Wilk_COVID

今天重复的内容是论文中的figure2f

今天的推文主要介绍其中的气泡图,明天的推文介绍如何向气泡图上叠加树形图
按照论文提供的代码得到了画图用到的数据,部分数据如下

但是用他提供的画图代码没有能够画出图来。因为他用到了一个dot_plot()
函数,没有找到这个函数是怎么来的。既然已经拿到了数据,就用ggplot2自己来画吧
读入数据
data.final<-read.csv("NM/figure2f.csv",header=T)
head(data.final)

基本的散点图
ggplot(data.final,aes(x=features.plot,y=id))+
geom_point()

用Average expression映射颜色,用Percent expressed映射点的大小
ggplot(data.final,aes(x=features.plot,y=id))+
geom_point(aes(size=`Percent expressed`,
color=`Average expression`))

接下来是设置主题的一些内容
包括
- 去掉灰色背景
- 调整坐标轴字体方向
- 去掉坐标轴标题
- 更改配色
ggplot(data.final,aes(x=features.plot,y=id))+
geom_point(aes(size=`Percent expressed`,
color=`Average expression`))+
theme_bw()+
theme(panel.grid = element_blank(),
axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5))+
scale_color_gradient(low="lightgrey",high="blue")+
labs(x=NULL,y=NULL)

欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!
遇到的问题:大家知道
dot_plot()
这个函数是哪来的吗?