一、gglogo
install.packages("gglogo")
library(gglogo)
data(sequences)
#加载sequences数据,是肽序列数据,是数据框格式
1.例一
ggplot(data = ggfortify(sequences, "peptide")) +
##这一步很重要,ggfortif 将数据转换成绘制logo plots的格式,对sequences数据进行一个统计,下图展示数据情况
geom_logo(aes(x = position, y = bits, group = element,
#x是以position数据绘制横轴,y是以bits数据绘制纵轴,group是分组
label = element, fill = interaction(Polarity, Water)),
#label是标签,fill是填充颜色的分组
alpha = 0.6) +
#alpha是柱状图透明度
scale_fill_brewer(palette = "Paired") +
#颜色
theme(legend.position = "bottom")
#图例位置
2.例二
ggplot(data = ggfortify(sequences, "peptide", treatment = "class")) +
geom_logo(aes(x=class, y=bits, group=element,
label=element, fill=element)) +
#根据element填充颜色
facet_wrap(~position, ncol=18) +
#根据position分面,成18列分布
theme(legend.position = "bottom")
3.例三
ggplot(data = ggfortify(sequences, "peptide", treatment = "class")) +
geom_logo(aes(x=position, y=bits, group=element, label=element, fill=element)) +
facet_wrap(~class, ncol=1) +
#根据class分面,成一
theme_bw()
#theme_bw 去掉背景色
4.例四
ggplot(data = ggfortify(sequences, "peptide", treatment = "class")) +
geom_logo(aes(x=class, y=bits, group=element,
label=element, fill=interaction(Polarity, Water))) +
scale_fill_brewer("Amino-acids properties", palette="Paired") +
facet_wrap(~position, ncol=18) +
theme(legend.position="bottom") +
xlab("") + ylab("Shannon information in bits")
#xlab,ylab修改坐标轴名称
二、logo
用logo绘制简单的序列标志图
library(RColorBrewer)
cols <- rep(brewer.pal(12, name="Paired"),22)
logo(sequences$peptide) + aes(fill=element) +
scale_fill_manual(values=cols)