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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:15:44+00:00 2026-06-11T17:15:44+00:00

I have a data frame like A B C D E F 2003-07 445

  • 0

I have a data frame like

    A   B   C   D   E   F
2003-07 445 48  1126    512 277 677
2003-08 429 77  1179    583 320 675
2003-09 421 80  1077    488 288 627

I want to plot these time series on the same graph. I also want A B C to have the same colour (blue) and the others to be black. So I use

ts.plot(df,col=c(rep("blue",3),rep("black",3)))

This creates the correct time series plot, except the colours are applied to the wrong series: A B C are a mix of blue and black and so are D E F. (Note that the real data frame has a lot more columns if that is the source of the problem.)

What order does ts.plot() use?

EDIT

df <- structure(list(X = structure(1:3, 
.Label = c("2003-07", "2003-08", "2003-09"), class = "factor"), 
 A = c(445L, 429L, 421L), B = c(48L, 77L, 80L),
 C = c(1126L, 1179L, 1077L), D = c(512L, 583L, 488L ), 
 E = c(277L, 320L, 288L), FF = c(677L, 675L, 627L)), 
.Names = c("X", "A", "B", "C", "D", "E", "FF"), 
class = "data.frame", row.names = c(NA, -3L))
  • 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-11T17:15:45+00:00Added an answer on June 11, 2026 at 5:15 pm
    ts.plot(df,col=c(rep("blue",3),rep("black",3)))
    

    I think it is plotting absolutely as specified in the order A-B-C-D-E-F.
    So…

    A     B     C     D     E     F
    Blue  Blue  Blue  Black Black Black 
    

    enter image description here

    If you match up your values for A/B/C…

              A  B    C
    2003-07 445 48 1126
    2003-08 429 77 1179
    2003-09 421 80 1077
    

    …you will see the three blue lines are those going from 445->429->421 & 48->77->80 & 1126->1179->1077, which actually matches what you specified you want.

    As an aside, you could simplify your plot call to be:

    ts.plot(df,col=rep(c("black","blue"),each=3))
    

    …by using the each= part of the function call.

    EDIT::

    Looking at your dput, it looks like your graph is also plotting your labels df$X as the values 1,2,3 since it is a factor and gets interpreted as such when plotting.

    Try this bit of code to remove the labels from your original plot and add them back in again:

    ts.plot(df[-1],col=c(rep("blue",3),rep("black",3)),gpars=list(xaxt="n"))
    axis(1,labels=as.character(df$X),at=1:3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data.frame that looks like this: 320 Dutch A7 3 321 Dutch
I have a data frame like below (20,000 rows by 49 cols). Each row
I have a data frame with gaps like this: Var1 Var2 Var3 1 NA
I have a data.frame that looks like this: > head(ff.df) .id pio caremgmt prev
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame in R that looks like this: > TimeOffset, Source,
I have a data.frame of a time series of data, I would like to
I have a large data.frame displaying some weird properties when plotted. I'd like to
I have the following data test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10)) I would like a barplot with
I have a dataframe with numeric entries like this one test <- data.frame(x =

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.