zhengzh

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包)

 

分类:

技术点:

相关文章:

  • 2021-10-19
  • 2021-12-26
  • 2021-12-18
  • 2022-01-10
  • 2021-10-19
  • 2021-10-19
  • 2021-11-02
  • 2021-07-05
猜你喜欢
  • 2021-10-19
  • 2021-10-19
  • 2021-08-31
  • 2021-09-05
  • 2021-09-19
  • 2021-06-24
  • 2021-10-19
相关资源
相似解决方案