Sos! "Lines" doesn't add plots to an existing plot...

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Sos! "Lines" doesn't add plots to an existing plot...

LosemindL
I am lost:

> plot(testError, col="red")
> lines(testVar, col="black")

Only one plot (the red one) appear on the Window, the black line did not
appear...what's wrong?

Thanks a lot!

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Sos! "Lines" doesn't add plots to an existing plot...

Dieter Menne
Michael <comtech.usa <at> gmail.com> writes:

> > plot(testError, col="red")
> > lines(testVar, col="black")
>
> Only one plot (the red one) appear on the Window, the black line did not
> appear...what's wrong?

We can only guess, because you did not supply the data. But I am quite sure,
that the lines-data are outside the range set by plot, probable because it
were "errors", i.e. differences to the original data. Try

plot(testVar, col="red")
lines(testError, col="black")

or use xlim as parameter of plot

Dieter

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Sos! "Lines" doesn't add plots to an existing plot...

barry rowlingson
In reply to this post by LosemindL
Michael wrote:

>>plot(testError, col="red")
>>lines(testVar, col="black")
>
>
> Only one plot (the red one) appear on the Window, the black line did not
> appear...what's wrong?

Hang on a second, just let me hack into your machine so I can find out
what 'testError' and 'testVar' are....

I'm guessing that the lines for 'testVar' are outside the range of the
plot formed by 'testError', but this is a guess and it could be a
bazillion other things. We have no way of knowing unless you tell is the
first things about testError and testVar.

For starters, try telling us what:

  str(testVar)
  str(testError)
  summary(testVar)
  summary(testError)

say.

Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Sos! "Lines" doesn't add plots to an existing plot...

Ted.Harding
In reply to this post by LosemindL
On 31-Jan-06 Michael wrote:

> I am lost:
>
>> plot(testError, col="red")
>> lines(testVar, col="black")
>
> Only one plot (the red one) appear on the Window, the black line did
> not
> appear...what's wrong?
>
> Thanks a lot!

Check the ranges of values of your two variables (in both x and y
directions in general, though x is probably not relevant to your
case since your implicit x-values are the indices of the y-values).

The first "plot" determines the ranges of values which will be
plotted, according to the range of values in the variables in
that plot, and these are held fixed when "lines" is called.

If, therefore, the y-values of "testVar" lie beyond the range
in the frame drawn by "plot", nothing will be plotted inside
that frame.

There are several possible ways of looking at this issue, but
they all come down finally to setting ylim=c(yMin,yMax)
and/or xlim=c(xMin,xMax) as arguments to the first "plot".
They vary in how you arrive at values for xMin, xMax, yMin, yMax.

For example, suppose you have daily temperatures for (in England)
the month of January (days 1-31 of the year) and July (182-212):

xJan<-(1:31)
yJan<-c( 2, 3, 6, 7, 5, 8,10,11, 8, 4,
        -1,-2, 0, 2, 6, 8, 9, 8, 6, 9,
        12,11, 9, 8, 5, 6, 8,10,11,10, 9)

xJul<-(182:212)
yJul<-c(17,20,21,20,19,22,25,26,28,27,
        25,24,22,25,26,23,19,20,19,22,
        20,23,25,24,21,19,22,25,28,26,27)

Now:

  plot(yJan,type="l",col="blue")
  lines(yJul,col="red")

exactly as you found: no red line! The plotted y-range is (-2,12),
and the yJul values lie outside this.

Next, note that the max value of yJul is 28, so:

  plot(yJan,type="l",col="blue",ylim=c(-2,28))
  lines(yJul,col="red")

so now you have the Jan and Jul temperatures for days 1:31 of
the month in each case.

But now:

  plot(xJan,yJan,type="l",col="blue",ylim=c(-2,28))
  lines(xJul,yJul,col="red")

and again the July plot is off the graph, because the x limits
were still set by the January x-values, and the July x-values
lie beyond this range. So, finally, noting that the x-values
range from 1 to 212 overall:

  plot(xJan,yJan,type="l",col="blue",xlim=c(1,212),ylim=c(-2,28))
  lines(xJul,yJul,col="red")

and now you have everything.

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <[hidden email]>
Fax-to-email: +44 (0)870 094 0861
Date: 31-Jan-06                                       Time: 07:54:01
------------------------------ XFMail ------------------------------

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Sos! "Lines" doesn't add plots to an existing plot...

PIKAL Petr
In reply to this post by LosemindL
Hi

most probably testError has different range then testVar, but only
you know if it is true.

What says

str(testError) and str(testVar)

HTH
Petr


On 30 Jan 2006 at 23:01, Michael wrote:

Date sent:       Mon, 30 Jan 2006 23:01:04 -0800
From:           Michael <[hidden email]>
To:             [hidden email]
Subject:         [R] Sos! "Lines" doesn't add plots to an existing plot...

> I am lost:
>
> > plot(testError, col="red")
> > lines(testVar, col="black")
>
> Only one plot (the red one) appear on the Window, the black line did
> not appear...what's wrong?
>
> Thanks a lot!
>
>  [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
[hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html