Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot error when points/lines have different date values to main plot #216

Closed
stewart123579 opened this issue Nov 20, 2017 · 2 comments
Closed
Assignees

Comments

@stewart123579
Copy link

Description

Plotting (with lines/points) a second set of data that is at different time points (i.e. xts2 below is 60 days between data points) to the first dataset (xts1 has 90 days between observations) results in the error:

Error in xy.coords(x, y) : 'x' and 'y' lengths differ

Expected behavior

Both curves/points plotted on the same chart. This was the previous behaviour of XTS.

Minimal, reproducible example

library(xts)

#####
# Create some data
# 3 monthly data
x1 <- seq(from = as.Date('2000-01-01'), to = as.Date('2010-12-31'), by = 90)
n <- length(x1)
y1 <- (c(1:n) - n / 2)^3
xts1 <- xts(y1, order.by = x1)
# 2 monthly data
x2 <- seq(from = as.Date('2000-01-01'), to = as.Date('2010-12-31'), by = 60)
y2 <- (c(1:length(x2)) - n / 2)^3
xts2 <- xts(y2, order.by = x2)


#####
# Plots

# Both datasets plot properly BY THEMSELVES
# Example 1 & 2
plot(xts1)
plot(xts2)

# Example 3
# This fails - 'xts1' first causes problems for 'xts1'
plot(xts1, main = "XTS plot")
points(xts2)

# Example 4
# This fails - 'xts2' plots, but then 'xts1' fails
plot(xts2, main = "XTS plot")
points(xts1)

# Example 5
# This works
plot.default(xts1, main = "Default plot")
lines.default(xts2)

## Order seems important
# Example 6
plot(xts1)
points(xts1)   # This plot works
points(xts2, col = "red")

# Example 7
plot(xts1)
points(xts2, col = "red")
points(xts1)  # Plotting after xts2 results in the same error

Session Info

R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] graphics  grDevices utils     datasets  stats     methods   base     

other attached packages:
[1] xts_0.10-0 zoo_1.8-0 

loaded via a namespace (and not attached):
[1] compiler_3.4.2  tools_3.4.2     grid_3.4.2      lattice_0.20-35
@joshuaulrich
Copy link
Owner

Thanks for the report! I can replicate the issues using the latest development version, and the error looks vaguely familiar.

@stewart123579
Copy link
Author

No problem. 😄

I've just checked and I don't think it is TZ related (c.f. #94).

@joshuaulrich joshuaulrich self-assigned this Dec 12, 2017
@joshuaulrich joshuaulrich added this to the Release 0.10-1 milestone Dec 12, 2017
joshuaulrich added a commit that referenced this issue Dec 26, 2021
Allow users to add a series to an existing plot when the new series
has x-values that do not exist in the original series. The only
restriction is that the new series cannot extend the x-axis beyond its
original start/end range.

The new behavior is consistent with chart_Series(). It looks like its
removal was a regression created when the 'observation.based = TRUE'
feature was implemented.

Fixes #360, see #216.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants