PDA

View Full Version : different colours for time series in splus



Magnolia
04-10-2009, 05:45 AM
Hi,

Iīm both new to this forum and fairly new to SPLUS (8.0 for Windows).
My problem is the following:
I want to display two time series on the same plot.
There are about 400 data points and the two time series lie very close to eachother. If I use plotting symbols (e.g. type="o", pch="18") the plot gets ridiculously messy. So Iīve decided to leave out the plotting symbols and simply use type="l". However since the time series are so close to eachother, itīs still impossible to tell which one is which. Different line types also donīt help.
So I need the second time series to be displayed in a different colour.
I tried the following:

ts.plot(series1, series2, type = "ll", col = c(1, 3), las = 1)

But the plot is still black and white.
If this is relevant: I need to put the plot into a LaTex document later, so after producing the plot, I have to export the graph (as jpeg) into some folder.

I would greatly appreciate any help, as all the time series plots Iīm doing are fairly useless at the moment without the different colours...

Thanks a lot!

Mike White
04-10-2009, 12:38 PM
I have tried your code with the example below and it works fine in S-Plus 6.2

library(MASS)
ts.plot(deaths, mdeaths, type = "ll", col = c(1, 3), las = 1)

However, it gives two lines types, so it is better to replace type with lty=c(1,1) to get both series as solid lines, e.g.

ts.plot(deaths, mdeaths, lty=c(1,1), col = c(1, 3), las = 1)

If the problem is caused by the lines overlapping too much you could try plotting the second series with an offset and create an offset secondary y axis as in the attached example.

Exporting as jpeg files is not recommended as the print quality can deteriorate if you enlarge the image, also it is not available on S-Plus (at least not in version 6.2). The attached example exports the graphic as a windows metafile.

Hope this helps.

Magnolia
04-10-2009, 01:54 PM
Thanks first of all.
I still donīt seem to manage to get the colours though.
I have included library(MASS) before ts.plot(...), but it doesnīt seem to work.
So I think I might not have access to this library.
I tried File<load library<MASS but the option "load library" is denied! Maybe this is because I have a free one year license from my university (downloaded SPLUS from a webpage rather than a CD)?
And Iīm afraid the example how to use offset is beyond my understanding of SPLUS at the moment, unfortunately..
donīt really know what to do, as I seem to need this library?

Mike White
04-10-2009, 02:49 PM
You should not need the MASS library, I only used it as it contains the deaths times series data. Are you sure that there is not a problem with your data, as you may only be plotting one series. You could try plotting each series separately and changing the colour to check that S-Plus is working as it should?

I you do not need to use S-Plus you could try using R. The language is almost the same.

Magnolia
04-10-2009, 02:52 PM
My university doesnīt allow R, only SPLUS.
And I am certain that both time series are displayed, as I have used the same commands for a different set of time series where the different lines donīt lie together that closely...

Magnolia
04-10-2009, 02:57 PM
This is really strange. I have now plotted only one time series and have chosen col=3 and it works! So colours do work afterall, and the problem comes in when there are more than one time series!

Magnolia
04-10-2009, 03:03 PM
The following command works:
> ts.plot(tourexp.ts, type="o", pch=16, cex=0.9, col=3)

But when I introduce a second time series:
> tmp <- tourexp.ts+tourexp.ts

the following command only generates a black and white plot:
> ts.plot(tourexp.ts, tmp, type="ll", col=c(1,3))

Mike White
04-10-2009, 03:28 PM
This is very strange! Can you confirm that for your last example with tourexp.ts and tmp the range of your y axis is about twice that with just plotting tourexp.ts.
The other thing you could try is replacing the parameter type="ll" with lty=c(1,1). When I try type="ll" I get one solid line and one dotted line.

Magnolia
04-11-2009, 02:03 AM
With the code:
> ts.plot(tourexp.ts, tmp, lty=c(1,1), col=c(1,3))
I get the plot in the attachment...
So I do get two solid lines (as opposed to one solid, one dashed with type="ll"), but still no colours!!! And as mentioned before the colours do seem to work if there is only one time series to be displayed... why does it mess up?

Mike White
04-11-2009, 03:17 AM
You could also check the menu settings under
Options/Graph Options and make sure Graph Styles is set to Colour in the drop down box

If I set Graph Styles to Black and White this over-rides the col=c(1,3) setting


Also might be worth looking at the options in
Options/Graph Styles/Colour

I am not sure but somewhere in this dialogue box there may be a setting for how the second colour in c(1,3) is interpretted.

You could also try different numbers in the col=c(1,3) to see if that makes a difference.

Magnolia
04-11-2009, 03:51 AM
Different colours donīt work either. Thanks for all your suggestions. Iīve tried them all - unfortunately without success. This is so frustrating! There is no reason why it shouldnīt work.
The only other idea I have is the following: I have noticed that when I plot only one time series in colour, not only the line of the time series is in colour, but also the left, top and right bar of the frame and the y-axis labels are in that colour. Is that normal? As maybe SPLUS gets confused when it is then asked to use an additional colour, as obviously frame and labels can only be displayed in a single colour? But doubt thatīs going to help...