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))
I think it is plotting absolutely as specified in the order
A-B-C-D-E-F.So…
If you match up your values for A/B/C…
…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:
…by using the
each=part of the function call.EDIT::
Looking at your
dput, it looks like your graph is also plotting your labelsdf$Xas the values1,2,3since it is afactorand 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: