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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:11:33+00:00 2026-05-14T18:11:33+00:00

I have 40 subjects, of two groups, over 15 weeks, with some measured variable

  • 0

I have 40 subjects, of two groups, over 15 weeks, with some measured variable (Y).

I wish to have a plot where: x = time, y = T, lines are by subjects and colours by groups.

I found it can be done like this:

TIME <- paste("week",5:20)
ID <- 1:40
GROUP <- sample(c("a","b"),length(ID), replace = T)
group.id <- data.frame(GROUP, ID)
a <- expand.grid(TIME, ID)
colnames(a) <-c("TIME", "ID")
group.id.time <- merge(a, group.id)
Y <- rnorm(dim(group.id.time)[1], mean = ifelse(group.id.time$GROUP =="a",1,3) )
DATA <- cbind(group.id.time, Y)
qplot(data = DATA,
        x=TIME, y=Y, 
        group=ID,       
        geom = c("line"),colour = GROUP) 

But now I wish to add to the plot something to show the difference between the two groups (for example, a trend line for each group, with some CI shadelines) – how can it be done?

I remember once seeing the ggplot2 can (easily) do this with geom_smooth, but I am missing something about how to make it work.

Also, I wondered at maybe having the lines be like a boxplot for each group (with a line for the different quantiles and fences and so on). But I imagine answering the first question would help me resolve the second.

Thanks.

  • 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-14T18:11:34+00:00Added an answer on May 14, 2026 at 6:11 pm
    p <- ggplot(data=DATA, aes(x=TIME, y=Y, group=ID)) +
                geom_line(aes(colour=GROUP)) +
                geom_smooth(aes(group=GROUP))
    

    geom_smooth plot http://img143.imageshack.us/img143/7678/geomsmooth.png

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

Sidebar

Related Questions

For reasons I will spare you, I have two weeks to learn some C++.
I have found some info on the subject ( like this link) , but
I have these two structures in my domain: Exercise (with subjects, solution, difficulty ext.)
I have two tables (subjects and pages) in one-to-many relations. I want to add
I have an array with subjects and every subject has connected time. I want
I have two MySQL tables, subjects and books, and a third table to define
I have two tables: subject and student. I'm trying to count the number of
Given: two images of the same subject matter; the images have the same resolution,
Let's say I have two tables, news and comments. news ( id, subject, body,
I have a problem finding references to this subject and would appreciate some help.

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.