ac <- read.csv("D:/High-throughput sequencing/!!!!GSE167940/RNA-seq/组蛋白修饰酶/ac.csv",header = T,row.names = 1)
me3 <- read.csv("D:/High-throughput sequencing/!!!!GSE167940/RNA-seq/组蛋白修饰酶/组蛋白修饰酶.csv",header = T,row.names = 1)
library(ggplot2)
library(tidyr)
library(dplyr)
#按行归一化;
hd_ac = t(scale(t(ac)))
hd_me3 = t(scale(t(me3)))
#预览数据;
head(hd_ac)
#转成数据框;
gene_ac <- row.names(hd_ac)
hf_ac <- data.frame(gene_ac,hd_ac)
gene_me3 <- row.names(hd_me3)
hf_me3 <- data.frame(gene_me3,hd_me3)
#转成长形数据;
dt_ac <- hf_ac %>% pivot_longer(
cols = !gene_ac,
values_drop_na = FALSE,
names_to = "groups",
values_to = "expressions")
dt_me3 <- hf_me3 %>% pivot_longer(
cols = !gene_me3,
values_drop_na = FALSE,
names_to = "groups",
values_to = "expressions")
#预览作图数据;
head(dt_ac)
转成因子,避免ggplot2自动排序;
#为了确保绘图顺序从上到下,可以颠倒level的顺序;
dt_ac$gene_ac <- factor(dt_ac$gene_ac,
levels = rev(unique(dt_ac$gene_ac)),
ordered = T)
dt_me3$groups <- factor(dt_me3$groups,
levels = unique(dt_me3$groups),
ordered = T)
#绘制热图,linewidth调整格子线粗细,color调整格子线颜色;
p_ac <- ggplot(dt_ac, aes(groups, gene_ac)) +
geom_tile(aes(fill = expressions),linewidth=0.4,
height=1,width=1,
colour = "black")+
scale_fill_gradient2(low = "#3FA9F5",
mid = "white",
high = "#FF931E",
midpoint = 0.5,
na.value = "grey92",
name="Exp")+
scale_x_discrete(position = "bottom")+
scale_y_discrete(position = "right")+
xlab('')+ylab('')+
theme(axis.text.x.bottom= element_text(angle = 45,face = "bold",
size=8,
hjust=0.3,vjust =0.5),
axis.text.y.right = element_text(angle = 0,face = "bold",
size=8,
hjust=1,vjust = 0.5),
panel.background = element_blank(),
legend.title = element_text(size = 6),
legend.position="left")+
guides(fill = guide_colourbar(direction = "vertical",
title.hjust=0,
title.position ="top",
ticks.colour="white",
frame.colour="purple",
barheight=5,
barwidth=0.7))+
coord_fixed(ratio = 1,expand=T)+
ggtitle("H3K27ac")
p_ac
p_me3 <- ggplot(dt_me3, aes(groups, gene_me3)) +
geom_tile(aes(fill = expressions),linewidth=0.4,
height=1,width=1,
colour = "black")+
scale_fill_gradient2(low = "#3FA9F5",
mid = "white",
high = "#FF931E",
midpoint = 0.5,
na.value = "grey92",
name="Exp")+
scale_x_discrete(position = "bottom")+
scale_y_discrete(position = "right")+
xlab('')+ylab('')+
theme(axis.text.x.bottom= element_text(angle = 45,face = "bold",
size=8,
hjust=0.3,vjust =0.5),
axis.text.y.right = element_text(angle = 0,face = "bold",
size=8,
hjust=1,vjust = 0.5),
panel.background = element_blank(),
legend.title = element_text(size = 6),
legend.position="left")+
guides(fill = guide_colourbar(direction = "vertical",
title.hjust=0,
title.position ="top",
ticks.colour="white",
frame.colour="purple",
barheight=5,
barwidth=0.7))+
coord_fixed(ratio = 1,expand=T)+
ggtitle("H3K4me3")
p_me3
【傻瓜美图】ggplot2热图
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- ggplot2是一款强大的绘图R包,今天的笔记内容是学习使用ggplot2来绘制一幅热图,并进行美化调整。需要加载...
- 热图系列快接近尾声了,这节我们讲下ggplot做的热图。实际上,之前heatmap已经足够了,但是ggplot2画...
- 很久之前我们出过热图系列,一共有6篇文章,反响还是可以,但是最近发现很多新关注的小伙伴没有翻看的习惯,居然不知道,...
- 论文 Single-cell profiling of vascular endothelial cells re...
- 论文是 De novo assembly, annotation, and comparative analysi...