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

moved col length checks to cover multi.panel = T as well as being num… #424

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ chart.lines <- function(x,
if(is.null(col))
col <- xx$Env$theme$col

if(length(lty) < NCOL(x)) lty <- rep(lty, length.out = NCOL(x))
if(length(lwd) < NCOL(x)) lwd <- rep(lwd, length.out = NCOL(x))
if(length(col) < NCOL(x)) col <- rep(col, length.out = NCOL(x))
# ensure pars have ncol(x) elements
lty <- rep(lty, length.out = NCOL(x))
lwd <- rep(lwd, length.out = NCOL(x))
col <- rep(col, length.out = NCOL(x))

for(i in NCOL(x):1) {
# x-coordinates for this column
Expand Down Expand Up @@ -360,7 +361,16 @@ plot.xts <- function(x,
grid2="#F5F5F5",
legend.loc=NULL,
extend.xaxis=FALSE){


# check for colorset or col argument
if(hasArg("colorset")) {
col <- eval.parent(plot.call$colorset)
}
# ensure pars have ncol(x) elements
col <- rep(col, length.out = NCOL(x))
lty <- rep(lty, length.out = NCOL(x))
lwd <- rep(lwd, length.out = NCOL(x))

# Small multiples with multiple pages behavior occurs when multi.panel is
# an integer. (i.e. multi.panel=2 means to iterate over the data in a step
# size of 2 and plot 2 panels on each page
Expand All @@ -370,12 +380,6 @@ plot.xts <- function(x,
idx <- seq.int(1L, NCOL(x), 1L)
chunks <- split(idx, ceiling(seq_along(idx)/multi.panel))

# allow color and line attributes for each panel in a multi.panel plot
if(length(lty) < ncol(x)) lty <- rep(lty, length.out = ncol(x))
if(length(lwd) < ncol(x)) lwd <- rep(lwd, length.out = ncol(x))
if(length(col) < ncol(x)) col <- rep(col, length.out = ncol(x))


if(!is.null(panels) && nchar(panels) > 0){
# we will plot the panels, but not plot the data by column
multi.panel <- FALSE
Expand Down Expand Up @@ -475,11 +479,6 @@ plot.xts <- function(x,
# lines of margin to the 4 sides of the plot: c(bottom, left, top, right)
cs$Env$mar <- if (hasArg("mar")) eval.parent(plot.call$mar) else c(3,2,0,2)

# check for colorset or col argument
# if col has a length of 1, replicate to NCOL(x) so we can keep it simple
# and color each line by its index in col
if(hasArg("colorset")) col <- eval.parent(plot.call$colorset)
if(length(col) < ncol(x)) col <- rep(col, length.out = ncol(x))
cs$Env$format.labels <- format.labels
cs$Env$yaxis.ticks <- yaxis.ticks
cs$Env$major.ticks <- if (isTRUE(major.ticks)) "auto" else major.ticks
Expand All @@ -488,11 +487,6 @@ plot.xts <- function(x,
cs$Env$grid.ticks.lwd <- grid.ticks.lwd
cs$Env$grid.ticks.lty <- grid.ticks.lty
cs$Env$type <- type

# if lty or lwd has a length of 1, replicate to NCOL(x) so we can keep it
# simple and draw each line with attributes by index
if(length(lty) < ncol(x)) lty <- rep(lty, length.out = ncol(x))
if(length(lwd) < ncol(x)) lwd <- rep(lwd, length.out = ncol(x))
cs$Env$lty <- lty
cs$Env$lwd <- lwd

Expand Down
Loading