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
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.
The workaround which I found was that instead of merging the two plots, I merged the data. I added an additional column at the end of the two dataframes and then performed the rbind
operation on them.The using either the fill
or color
aesthetics to separate the two plots. Of course in my case the scale used for the axis were to be the same.