1. 效果图
2. 预处理及绘图
# 输入数据
> head(dat)
Species cid variable value
1 setosa 1 Sepal.Length 5.1
2 setosa 2 Sepal.Length 4.9
3 setosa 3 Sepal.Length 4.7
4 setosa 4 Sepal.Length 4.6
5 setosa 5 Sepal.Length 5.0
6 setosa 6 Sepal.Length 5.4
# 预处理及绘图
row.num=nrow(iris)
dat=iris[1:row.num,] #假设有4个时间点,最后一列是聚类结果
dat$cid=rownames(dat) #很重要!用于 ggplot 的 group
head(dat)
#宽变长
dat = tidyr::gather(data = dat, key = "variable", value = "value", -c(Species, cid))
# or: 宽变长
#dat=reshape2::melt(dat)
# 限定x轴顺序
dat$variable=factor(dat$variable, levels = c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width'))
head(dat)
dim(dat)
ggplot(dat, aes(x=variable, y=value, group=cid, color=Species))+
geom_hline(yintercept =4, linetype=2, size=0.5) +
geom_line(size=0.3)+
stat_summary(aes(group=1),fun.y=mean, geom="line", size=0.8, color="black")+
facet_wrap(Species~.)+
labs(x="Stage", y='Expression')+
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.text = element_text(size=8, face = "bold"),
axis.text.x=element_text(angle=60, hjust=1),
strip.background = element_rect(fill="white"),
strip.text = element_text(size = 8, face = "bold"))