annotate(ggplot2)

ggplot2中的annotate可以在已有图形基础上,添加任意几何对象(如rect,pointrange,text等)

ggplot(ct1, aes(x=pos, group=Feature, weight=weight))  +
        scale_x_continuous(minor_breaks = seq(0, 5, 1)) + 
        ggtitle("Distribution on mRNA") +
        theme(axis.ticks = element_blank(), axis.text.x = element_blank()) + 
        xlab("") + 
        ylab("Frequency") +
        geom_density(adjust=adjust,aes(fill=factor(Feature),colour=factor(Feature)),alpha=0.2) +
        annotate("text", x = sum(x1[1:2])/2, y = -0.2, label = "5'UTR") +
        annotate("text", x = sum(x1[2:3])/2, y = -0.2, label = "CDS") +
        annotate("text", x = x1[1]/2, y = -0.2, label = "Promoter (1kb)") +
        annotate("text", x = sum(x1[4:5])/2, y = -0.2, label = "Tail (1kb)") +
        annotate("text", x = sum(x1[3:4])/2, y = -0.2, label = "3'UTR")  + 
        geom_vline(xintercept=x1[1:4], linetype="dotted") + 
        annotate("rect", xmin = x1[1], xmax = x1[2], ymin = -0.12, ymax = -0.08, alpha = .99, colour = "black")+
        annotate("rect", xmin = x1[3], xmax = x1[4], ymin = -0.12, ymax = -0.08, alpha = .99, colour = "black")+
        annotate("rect", xmin = x1[2], xmax = x1[3], ymin = -0.16, ymax = -0.04, alpha = .2, colour = "black") +
        xlim(0,1) +
        theme(legend.position="bottom")

上图最底层的长方形就是用annotate制作出来的(代码来自于Guitar包)

 

posted @ 2018-10-10 21:14  ZzzzHong  阅读(5508)  评论(1编辑  收藏  举报