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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:33:48+00:00 2026-05-29T05:33:48+00:00

I want to have multiple lines on the same plot. Multiple data points. In

  • 0

I want to have multiple “lines” on the same plot. Multiple data points.

In my example, how can I include the ‘xa’ and ‘xb’ data points.

This is what I have for just one set of data points but I want two. How can I modify this script.

library(ggplot2)

da <- c("2012-02-02 09:01:00", "2012-02-02 09:02:00", "2012-02-02 09:03:00")
db <- c(0.4, 0.6, 0.5)

xa <- c("2012-02-02 09:01:00", "2012-02-02 09:02:00", "2012-02-02 09:03:00")
xb <- c(0.3, 0.43, 0.7)

da2 <- as.POSIXct(da)
dfx <- data.frame(da2, db)

summary(dfx)

png('time_data_errs6b.png', width=640, height=480)
gg <- qplot(da2, db, colour='red')+
    opts(title = 'Requests App')+xlab('Time')+ylab('Requests') +
    geom_line()

print(gg)
dev.off()
  • 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-29T05:33:49+00:00Added an answer on May 29, 2026 at 5:33 am

    I would make two data.frames and merge them by the time variable.

    > df.a<-data.frame(time=da, value.a=db)
    > df.b<-data.frame(time=xa, value.b=xb)
    > df.mix<-merge(df.a, df.b, by='time')
    
    > df.mix
                     time value.a value.b
    1 2012-02-02 09:01:00     0.4    0.30
    2 2012-02-02 09:02:00     0.6    0.43
    3 2012-02-02 09:03:00     0.5    0.70
    

    Convert to POSIXct like you did then melt it to a long format.

    > df.mix$time<-as.POSIXct(df.mix$time)
    > df.melt<-melt(df.mix, id.vars='time')
    

    ggplot deals with long format data very well, so its usually my goal to get data into a suitable structure with melt and merge before plotting.

    > ggplot(df.melt, aes(x=time, y=value, colour=variable)) + geom_path()
    

    I also like to uses the base ggplot rather than qplot for my own readability. but thats a matter of preference.

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

Sidebar

Related Questions

I want to have a tree in memory, where each node can have multiple
I have multiple SharePoint lists and want to display data from them on to
I have multiple images that have the same class attribute and I want to
I am using Ruby. I have a string with multiple lines. I want to
We have multiple vb projects.We want to put error handlers in all functions, and
I have multiple excel files which I open as datatable I want to merge
I have multiple document.ready functions on a page and I want a function to
I have multiple (8) WAR files and 1 EAR file that I want to
I have multiple rave reports(projects) in the project(the delphi project) and I want to
I have multiple processes monitoring an MSMQ queue. I want to do multi-step operations

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.