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 7029213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:30:33+00:00 2026-05-28T00:30:33+00:00

I have a tricky question regarding to what i’m trying to do. I have

  • 0

I have a tricky question regarding to what i’m trying to do.
I have a plot with two lines (the mean of two conditions) on it. I want to add on the same plot a square reflecting the t-values (and colored according to these values in a gradient way). How could i add this square?

Well since i don’t know if i’m clear, here is a figure of what i try to achieve.

Thank you for any help!

enter image description here

  • 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-05-28T00:30:34+00:00Added an answer on May 28, 2026 at 12:30 am

    Try this for ggplot2 way:

    x <- seq(-10, 10, 0.1)
    df <- data.frame(x, y1 = pnorm(x), y2 = pnorm(x) * 2)
    df$t <- df$y2 - df$y1
    dfm <- melt(df, id = "x")
    
    ggplot(NULL, aes(x, value)) + 
      geom_line(aes(colour = variable), 
                droplevels(subset(dfm, variable %in% c("y1", "y2")))) +
      geom_rect(aes(xmin = x - 0.05, xmax = x + 0.05, ymin = -0.5, ymax = -0.4, fill = value),
                subset(dfm, variable == "t"))
    

    enter image description here

    UPDATED

    You can use scale_fill_XXX. Here is a jet-color version:

    jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
    
    # panel on the left side
    p <- ggplot(NULL, aes(x, value)) + 
      geom_line(aes(colour = variable), 
                droplevels(subset(dfm, variable %in% c("y1", "y2")))) +
      geom_rect(aes(xmin = x - 0.05, xmax = x + 0.05, ymin = -0.5, ymax = -0.4, fill = value),
                subset(dfm, variable == "t")) + 
      scale_fill_gradientn(colours = jet.colors(7))
    p
    

    and in the next version of ggplot2, you can use colorbar as the legend.

      # panel on the right side
      p + guides(fill = "colourbar")   
    

    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 have a tricky question regarding shallow serialization of List of objects my entities
I have a question regarding data frames in R. I want to take a
I have a tricky question (at least in my perspective), regarding Scalas parser combinators
I have a tricky question. lets say if we start naming session as :
I have a small tricky question with nested arrays. I am getting something like
Tricky question. I have a very long form where the user writes down a
I have a question regarding variable linking between objects. Because I'm learning Python programming
A little question regarding performance in a Java web app. Let's assume I have
I have a tricky question and I'm not sure if it is even possible
I have a very tricky question for you all Suppose I have the following

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.