Skip to content

Commit

Permalink
Fixed bug in ggsubseriesplot when labels provided
Browse files Browse the repository at this point in the history
  • Loading branch information
robjhyndman committed Jul 23, 2024
1 parent ace207e commit 97a0a4a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions R/ggplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1251,14 +1251,7 @@ ggsubseriesplot <- function(x, labels = NULL, times = time(x), phase = cycle(x),

# Create x-axis labels
xfreq <- frequency(x)
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
}
}
else if (xfreq == 4) {
if (xfreq == 4) {
xbreaks <- c("Q1", "Q2", "Q3", "Q4")
xlab <- "Quarter"
}
Expand All @@ -1277,6 +1270,13 @@ ggsubseriesplot <- function(x, labels = NULL, times = time(x), phase = cycle(x),
xbreaks <- 1:frequency(x)
xlab <- "Season"
}
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
}
}

# X-axis
p <- p + ggplot2::scale_x_continuous(breaks = 0.5 + (1:xfreq), labels = xbreaks)
Expand Down

0 comments on commit 97a0a4a

Please sign in to comment.