Overlaying two graphs using ggplot2 in R

后端 未结 2 1112
长发绾君心
长发绾君心 2020-12-05 10:25

I have two graphs and I am trying to overlay one on top of the other:

An example of the data frame \"ge\" looks like this. In actuality there are 10 Genes with 200

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 10:49

    One way is to add the geom_line command for the second plot to the first plot. You need to tell ggplot that this geom is based on a different data set:

    ggplot(avg, aes(x=Gene, y=mean)) + 
      geom_point() + 
      geom_line() + 
      geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), width=.1) +
      geom_line(data = ge, aes(x=Gene, y=Exp, group=Sample, colour="#000099"),
                show_guide = FALSE)
    

    The last geom_line command is for creating the lines based on the raw data. enter image description here

提交回复
热议问题