Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:29:55+00:00 2026-06-14T15:29:55+00:00

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

  • 0

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 samples each, so there are 2000 rows and 3 columns:

Exp    Gene    Sample
903.0   1       1
1060.0  1       2
786.0   1       3
736.0   1       4
649.0   2       1
657.0   2       2
733.5   2       3
774.0   2       4

An example of the data frame “avg” looks like this. This is an average of the data points for each gene across all samples. In actuality this graph has 10 genes, so the matrix is 4col X 10 rows:

mean       Gene   sd         se
684.2034    1   102.7142    7.191435
723.2892    2   100.6102    7.044122

The first graph graphs a line of the average expression for each gene along with the standard deviation for each data point.

avggraph <- ggplot(avg, aes(x=Gene, y=mean)) + geom_point() +geom_line() + geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), width=.1)

The second graph graphs the gene expression in the form a line for each sample across all the genes.

linegraphs <- ggplot(ge, aes(x=Gene, y=Expression, group=Samples, colour="#000099")) + geom_line() + scale_x_discrete(limits=flevels.tge)

I would like to superimpose avggraph on top of linegraphs. Is there a way to do this? I’ve tried avggraph + linegraphs but I’m getting an error. I think this is because the graphs are generated by two different data frames.

I should also point out that the axes of both graphs are the same. Both graphs have the genes on the X-axis and the gene expression on the Y-axis.

Any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:29:56+00:00Added an answer on June 14, 2026 at 3:29 pm

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have two data series plotted in one graph as boxes
For example I have a website that points to a page like this: http://www.mysite.com/folder/file
I am trying to display 3 Highcharts-generated graphs on one page. I have loaded
I am trying to make one figure by stacking two graphs (a) and (b)
I'm trying to get this graphing calculator to work. I have two view controllers,
I am trying create a data.frame from which to create a graph. I have
I am trying to merge two ggplot2 plots into one based on this table:
I have the data in two files. I want to plot a graph the
With this approach. I have a line plot graph. I want to plot 'two'
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.