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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:33:05+00:00 2026-06-16T00:33:05+00:00

Basically I’d like to create the first plot shown below in R using ggplot,

  • 0

Basically I’d like to create the first plot shown below in R using ggplot, but with both objects on the same graph (no facet wrapping).

Consider a minimal example that mimics my data structure:

library(reshape2)
library(ggplot2)
x <- seq(1, 5, length = 100)
y <- replicate(10, sin(2 * pi * x) + rnorm(100, 0, 0.3), "list")
z <- replicate(10, sin(2 * pi * x) + rnorm(100, 5, 0.3), "list")
y <- melt(y)
z <- melt(z)
df <- data.frame(x = y$Var1, rep = y$Var2, y = y$value, z = z$value)
dat <- melt(df, id = c("x", "rep"))

I can plot it with

ggplot(dat) + geom_line(aes(x, value, group = rep, color = variable), 
    alpha = 0.3) + facet_wrap(~variable)

And get


(source: carlboettiger.info)

But if I try dropping the facet wrapping, I thought it should group by color and variable, but instead the data are not broken out correctly, resulting in nonsense:


(source: carlboettiger.info)

  • 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-16T00:33:06+00:00Added an answer on June 16, 2026 at 12:33 am

    The problem is that the group aesthetic overrides the standard grouping protocols – it isn’t included in the interaction of all discrete variables in the plot described in ?group.

    So, to get your plot to work without faceting you would need to manually specify the interaction

    ggplot(dat) + geom_line(aes(x, value, group = interaction(rep,variable), color = variable), alpha = 0.3) 
    

    enter image description here

    To override the alpha value in the aesthetic, use guide_legend(override.aes = ...)). This information can be found following the links in ?guides and specifically ?guide_legend

    eg

    ggplot(dat) + geom_line(aes(x, value, group = interaction(rep,variable), color = variable), 
                               alpha = 0.3) + 
      scale_colour_discrete(guide = guide_legend(override.aes = list(alpha = 1)))
    

    enter image description here

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

Sidebar

Related Questions

Basically, I am making a XML stylesheet. So I am using the below method:
Basically i'd like to allow an arbitrary (but not empty ) number of key-value
Basically, what I'm trying to create is a page of div tags, each has
Basically I am trying to do this: <Trigger Property=Item Value={c:CollectionView.NewItemPlaceHolder}> But the syntax is
Basically I need some text like: I have an ice cream cone. You are
Basically I have 2 strings. They are EXACTLY the same string. However, when I
Basically, I have an object that I think should be garbage-collected but it's not.
Basically when user resizes my application's window I want application to be same size
Basically I have two ways for writing something First: <?php echo link_to( static_image_tag( $object->getImageWebPath(),
Basically I want to create a user control in code behind, DataBind() it and

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.