6
$\begingroup$

I need to draw two time-series plots on a graph in R. The problem I am facing is as follows. Each plot has 200 data points, and therefore, the graph that I have produced looks clumsy on my two-column pdf file. I am trying to use different pch values, but still the graph doesn't look good to me. Could someone help me to visualize this data in an elegant way, please? Please see the graph below. The most important requirement is that the graph should be clear on printing.

The R Code that I have used is as follows:

plot(temp11, type="b", col="blue", ylim=c(0.5,1), lwd=0.8, lty=4, pch=1, xlab="Time", ylab="price", cex.lab=1.2,cex.axis=1.2)
> lines(temp22, type="b", col="red", lwd=1.5,lty=1, pch=18)
> legend("top",legend=c("temp11","temp22"),lty=c(4,1),pch=c(1,18), col=c("blue", "red"),text.col=c("blue", "red"))

enter image description here

$\endgroup$
5
  • 2
    $\begingroup$ maybe losing the plotting characters altogether and increasing the line width (argument: lwd. takes positive real values) would made it reasonable. How does this example x=ts(rnorm(100)); y=ts(rnorm(100)); plot(x, col=2, ylim=c(-4,4), lwd=4); lines(y, col=4, lwd=4) look? It would need to be suped-up a bit but I think that basic template makes both time series visible. $\endgroup$
    – Macro
    Aug 28, 2011 at 3:56
  • $\begingroup$ @Marco: Thanks. On a computer screen your idea is perfectly fine. But the graph should be elagant on printing. It would be great if you share your ideas further on this. $\endgroup$
    – samarasa
    Aug 28, 2011 at 4:02
  • 1
    $\begingroup$ Have you thought about two rows instead of two columns? Even if you decide to keep them both on the same axes, if you'd make your height smaller than your width then it'd stretch the series out to address that bunching up shown above. $\endgroup$
    – user1108
    Aug 28, 2011 at 5:29
  • $\begingroup$ @Jay: I am not getting your idea. Could you please give more information? Thank you. $\endgroup$
    – samarasa
    Aug 28, 2011 at 6:04
  • 1
    $\begingroup$ As @macro suggested, maybe lose the points altogether, or maybe just make them really small. You could use cex = .3, or pch = '.'. If you make them small,I would suggest filled circles instead of open circles. Given the overlap on the right side of the graph, though, it might be good to lose the lines and keep the dots, perhaps with a small amount of jitter to avoid overlap $\endgroup$
    – Peter Flom
    Aug 28, 2011 at 10:37

2 Answers 2

6
$\begingroup$

Partial transparency ("alpha") might help you here, e.g.:

> temp11=runif(100)
> temp22=runif(100)
> plot(temp11, type="p", col=rgb(0.2, 0.2, 1, 0.6), pch=19, xlab="Time", ylab="price")
> lines(temp11, lwd=3, col=rgb(0.2, 0.2, 1, 0.3))
> points(temp22, pch=19, col=rgb(1, 0.2, 0.2, 0.6))
> lines(temp22, lwd=3, col=rgb(1, 0.2, 0.2, 0.3))

Here is an example of the image: https://i.stack.imgur.com/PUdkm.png

It doesn't look that great with runif data, but on your data I think it would work a bit better. Alpha support is device-dependent, but PDF does support it.

$\endgroup$
1
  • $\begingroup$ Welcome to the site. With your couple of upvotes from this post you should have enough reputation to post as many images and links in questions/answers as you would like. $\endgroup$
    – Andy W
    Aug 28, 2011 at 21:08
5
$\begingroup$

Here's what I was trying to say in the comment, with a little bit more detail (though this might not be the answer to your question). First, get some data.

x <- arima.sim(200, model = list(ar = 0.6)) + 3
y <- arima.sim(200, model = list(ar = -0.7)) - 3

A plot with two columns would look something like this:

par(mfrow = c(1,2))
plot(x)
plot(y)

with a graph like so:

enter image description here

while a plot with two rows would look something like this:

par(mfrow = c(2,1))
plot(x)
plot(y)

with a graph like so:

enter image description here

And if you'd like to keep both series on the same axes then you could do like this:

par(mfrow = c(1,1))
ts.plot(x, y)

which would look something like this:

enter image description here

I was trying to communicate that if you make the plot wider rather than taller then it helps to see what's happening inside the lengthy time series better. You can manually resize the graphics device to get the aspect you like, or if you use RStudio, when you export the image you can set whatever dimensions desired.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.