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

ggsubseriesplot() throws error when only labels argument is provided; needs xlab argument to work #964

Closed
drgomulka opened this issue Jul 23, 2024 · 1 comment

Comments

@drgomulka
Copy link

This throws an error:

ggsubseriesplot(AirPassengers, labels = 1:12)
Error in ggAddExtras(ylab = deparse(substitute(x)), xlab = xlab) :
object 'xlab' not found
ggsubseriesplot(AirPassengers, labels = letters[1:12] )
Error in ggAddExtras(ylab = deparse(substitute(x)), xlab = xlab) :
object 'xlab' not found

Providing the function with a xlab argument makes it work:

ggsubseriesplot(AirPassengers, labels = 1:12, xlab="xlab argument needs to be set")
ggsubseriesplot(AirPassengers, labels = letters[1:12], xlab="Please set xlab argument")

The problem comes from this if block. It sets xbreaks, but does not set xlab.

forecast/R/ggplot.R

Lines 1254 to 1260 in ace207e

if (!is.null(labels)) {
if (xfreq != length(labels)) {
stop("The number of labels supplied is not the same as the number of seasons.")
} else {
xbreaks <- labels
}
}

The if blocks on lines 1261 to 1279 set both xbreaks and xlab.

forecast/R/ggplot.R

Lines 1261 to 1279 in ace207e

else if (xfreq == 4) {
xbreaks <- c("Q1", "Q2", "Q3", "Q4")
xlab <- "Quarter"
}
else if (xfreq == 7) {
xbreaks <- c(
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"
)
xlab <- "Day"
}
else if (xfreq == 12) {
xbreaks <- month.abb
xlab <- "Month"
}
else {
xbreaks <- 1:frequency(x)
xlab <- "Season"
}

@robjhyndman
Copy link
Owner

Thanks. Fixed in 97a0a4a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants