[R] Problem adding lines to a plot, when y is defined

Cech, Christian Christian.Cech at fh-vie.ac.at
Mon Sep 9 18:00:51 CEST 2013


Dear all,

I want to create a line-plot with two lines and some additional scatter-plots.
However, adding a line to the plot does not work when I specify the y-argument in the plot command, while it does work when y is not specified.

I first send you an example that works:
plot(var[, 3],
     type="l",
     ylim=c(-0.04, 0),
     ylab   = 'portfolio returns',
     xlab   = 'time')
lines(var[, 5], type="l", lty=3)
for (i in 1:nrow(var)) {
  if(var[i, 4] | var[i,6])
    points(i, var[i, 2], pch=4)
}

--> the result is displayed in attachment "Plot1.pdf"

What does not work is the following code, where as the first argument of plot (ie the y-argument) is defined:
plot(as.Date(var[, 1], origin="1899-12-30"),
     var[, 3],
     type="l",
     ylim=c(-0.04, 0),
     ylab='portfolio returns',
     xlab='time')
lines(var[, 5], type="l", lty=3)
for (i in 1:nrow(var)) {
  if(var[i, 4] | var[i,6])
    points(i, var[i, 2], pch=4)
}

--> the result is displayed in attachment "Plot2.pdf"

The same problem appears if instead of

as.Date(var[, 1], origin="1899-12-30")

I use

var[, 1]

to define the y-argument.

I do very much appreciate your help!
Kind regards,
Christian Cech

________________________________


Firmenwortlaut: Fachhochschule des bfi Wien Gesellschaft m.b.H
Firmenbuchnummer: 148597 a
Firmenbuchgericht: Handelsgericht Wien
Firmensitz: Wohlmutstraße 22, 1020 Wien

This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required please request a hard-copy version.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Plot1.pdf
Type: application/pdf
Size: 170140 bytes
Desc: Plot1.pdf
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130909/424ca860/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Plot2.pdf
Type: application/pdf
Size: 87948 bytes
Desc: Plot2.pdf
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130909/424ca860/attachment-0001.pdf>


More information about the R-help mailing list