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

  • Home
  • SEARCH
  • 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 6375847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:40:06+00:00 2026-05-25T01:40:06+00:00

I’ve managed to get ggplot2 to create almost the plot I want from a

  • 0

I’ve managed to get ggplot2 to create almost the plot I want from a data set, but I can’t figure out how to label my points.

Given data looking something like this:

sample <- data.frame(rowid=seq(100), a=runif(100), b=runif(100, .5, 1.5))

I can create a plot comparing these two things like this (looks less funny given my real and better labels, but this does a good approximation):

ggplot(data=sample) + 
      geom_point(aes(rowid, a), color="#990000", alpha=0.4) +
      geom_smooth(aes(rowid, a), color='#990000') +
      geom_point(aes(rowid, b), color='#000099', alpha=0.4) +
      geom_smooth(aes(rowid, b), color='#000099') +
      labs(x='Trial', y='Time')

How can I get that to have a legend displaying what the red and the blue are?

Edit

Thanks to a comment from baptiste, I now have the following:

wide = melt(sample, id="rowid")

ggplot(data=wide) + 
      geom_point(aes(rowid, value, color=variable), alpha=0.1) +
      scale_alpha(0.3) +
      scale_colour_manual(name="Variables", values=c("b"="#990000", "a"="#000099")) +
      geom_smooth(aes(rowid, value, color=variable)) +
      labs(x='Trials', y='Time')
  • 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-25T01:40:06+00:00Added an answer on May 25, 2026 at 1:40 am

    Baptiste pointed you in the right direction by suggesting using melt from the reshape2 package.

    To control the alpha of your points and smoother separately, simply specify the alpha you desire in each geom. Note that the scale_alpha statement in your example code does nothing, because alpha was not mapped to any aesthetic, so I removed this. Also, since your mapping is identical to all layers, this is easier to specify in the ggplot paramaters rather than the geom parameters:

    sample <- data.frame(rowid=seq(100), a=runif(100), b=runif(100, .5, 1.5))
    wide = melt(sample, id="rowid")
    
    ggplot(data=wide, aes(x=rowid, y=value, color=variable)) + 
        geom_point(alpha=0.1) +
        scale_colour_manual(name="Variables", values=c("b"="#990000", "a"="#000099")) +
        geom_smooth(alpha=0.8) +
        labs(x='Trials', y='Time')
    

    enter image description here

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

Sidebar

Related Questions

No related questions found

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.