首先是示例数据
![](https://img.haomeiwen.com/i6857799/fe8afd060080181c.png)
使用R语言的ggplot2做一个热图
#install.packages("see")
df<-read.csv("20210809_example.csv")
library(ggplot2)
library(see)
ggplot(data=df,aes(x=gene_name,y=variable))+
geom_tile(aes(fill=value))+
scale_fill_social_c()
![](https://img.haomeiwen.com/i6857799/b595d88b6d0c4e60.png)
增加y轴的上下空白
ggplot(data=df,aes(x=gene_name,y=variable))+
geom_tile(aes(fill=value))+
scale_fill_social_c()+
scale_y_discrete(expand=expansion(mult=1))
![](https://img.haomeiwen.com/i6857799/a9e5bdd6b918c891.png)
增加下方的空白
ggplot(data=df,aes(x=gene_name,y=variable))+
geom_tile(aes(fill=value))+
scale_fill_social_c()+
scale_y_discrete(expand=expansion(mult=c(1,0)))
![](https://img.haomeiwen.com/i6857799/8c59907aa1d61fad.png)
如果是要更改x轴左右的间距把scale_y_discrete()
换成scale_x_discrete()
就可以了
这个有啥用,其中一个用途是画环状热图的时候可以增加中间的空白区域
比如默认环状热图
ggplot(data=df,aes(x=gene_name,y=variable))+
geom_tile(aes(fill=value))+
coord_polar()+
scale_fill_social_c()+
theme_void()
![](https://img.haomeiwen.com/i6857799/4bda4b5cefc84028.png)
设置中心空白
ggplot(data=df,aes(x=gene_name,y=variable))+
geom_tile(aes(fill=value))+
coord_polar()+
scale_fill_social_c()+
theme_void()+
scale_y_discrete(expand=expansion(mult=c(1,0)))
![](https://img.haomeiwen.com/i6857799/651d0b14b06c76e4.png)
增加开口
ggplot(data=df,aes(x=gene_name,y=variable))+
geom_tile(aes(fill=value))+
coord_polar()+
scale_fill_social_c()+
theme_void()+
scale_y_discrete(expand=expansion(mult=c(1,0)))+
scale_x_discrete(expand=expansion(mult=c(0,0.2)))
![](https://img.haomeiwen.com/i6857799/aa10c9ddd7fdea64.png)
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!
网友评论