[Rd] problem plotting "ts" in a data.frame

Spencer Graves spencer.graves at prodsyse.com
Wed Feb 10 18:02:05 CET 2016

On 2/10/2016 9:43 AM, Martyn Plummer wrote:
> On Tue, 2016-02-09 at 16:56 -0600, Spencer Graves wrote:
>> Hello:
>>         I'm having trouble plotting an object of class "ts" that is in a
>> data.frame.  I can do it with(data.frame, plot(...)) but not with
>> plot(..., data.frame);  see the example below.
> The plot function is generic so the actual function call depends on what
> arguments you give it: plot(y.ts) calls the plot.ts method from the
> stats package, whereas plot(y.ts ~ x) calls the plot.formula method from
> the graphics package. Only the plot.formula method has a data argument.
> What happens when you call plot(y1~x1, data=XY) is that first
> plot.formula is called and then this calls plot.ts with two arguments
> (XY$x1 and XY$y1) that are expected to be compatible time series.
> However, they are not. In fact x1 is numeric and when coerced to a time
> series it has no time points in common with y1 (which starts at time
> t=5). Hence the warning about non-intersecting series.
> Since non-overlapping series seems to be fatal in this context it might
> be a good idea to give an error at this point. Otherwise I think the
> function is behaving correctly.
> Martyn

Hi, Martyn:

       Thanks for the reply.  I think it's interesting that "plot(x1~y1, 
XY)" works roughly as I would have expected, as does 
"plot(as.numeric(y1)~x1, XY)".  However, "plot(y1~x1, XY)" stops with 
"need finite 'xlim' values" after arriving at "plot.window".  I found 
that quite cryptic.

       In any case, that's for your contributions to R and for 
responding to my question.


>>         This work around gets me past this problem.  However, I thought
>> the R Core team might want to know about this if they don't already.
>>         Thanks for all your work in making R and CRAN the great tools
>> that they are -- and I apologize for wasting your time if you are
>> already familiar with this.
>>         Spencer Graves
>>   > y.ts <- ts(2:4, 5)
>>   > XY <- data.frame(x1=6:8, y1=y.ts)
>>   > plot(y1~x1, XY)
>> Error in plot.window(...) : need finite 'xlim' values
>> In addition: Warning messages:
>> 1: In .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union =
>> FALSE) :
>>     non-intersecting series
>> 2: In min(x) : no non-missing arguments to min; returning Inf
>> 3: In max(x) : no non-missing arguments to max; returning -Inf
>> 4: In min(x) : no non-missing arguments to min; returning Inf
>> 5: In max(x) : no non-missing arguments to max; returning -Inf
>>   > plot(y1, XY)
>> Error in plot(y1, XY) : object 'y1' not found
>>   > with(XY, plot(y1))
>>   > sessionInfo()
>> R version 3.2.3 (2015-12-10)
>> Platform: x86_64-apple-darwin13.4.0 (64-bit)
>> Running under: OS X 10.11.2 (El Capitan)
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods base
>> loaded via a namespace (and not attached):
>> [1] tools_3.2.3
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
> -----------------------------------------------------------------------
> This message and its attachments are strictly confiden...{{dropped:9}}

More information about the R-devel mailing list