ggplot2 doesn't know how to automatically pick scale for <ts> object

I'm learning about time series object, ts. I used datasets::AirPassenger as the ts object.
To plot the time series with ggplot2, I do one of the following:
(1) Coerce the ts object to a tibble using tk_tbl() in the timetk package.
(2) Coerce the ts to a tibble with as_tibble() and extract the time component using as.yearmon() in the zoo package.
(3) Coerce the ts to a tibble with as_tibble() and extract the time component using date_decimal() in the lubridate package.
All the three methods produce correctly the time series plot. But for methods (2) and (3), I received the message " Don't know how to automatically pick scale for object of type . Defaulting to continuous."

How do I avoid the message from R? I was obviously using a tibble and not a ts. Secondly the output from method (1) and (2) produced similar tibbles but method (1) did not elicit the message while (2) did.
Am I missing something in my understanding of the ts object?

Here are my code:
library(tidyverse)

passengers_tb <- timetk::tk_tbl(AirPassengers, rename_index = "date")

passengers_tb1 <- as_tibble(AirPassengers) |>
rename(value = x) |>
add_column(date = zoo::as.yearmon(time(AirPassengers)), .before = "value")

passengers_tb2 <- as_tibble(AirPassengers) |>
rename(value = x) |>
add_column(date = lubridate::date_decimal(as.numeric(time(AirPassengers))), .before = "value")

ggplot(passengers_tb, aes(x = date, y = value)) +
geom_line() +
labs(title = "(1) Monthly Air Passengers (1949-1960)", x = "Year", y = "Passengers") +
theme_minimal()

ggplot(passengers_tb1, aes(x = date, y = value)) +
geom_line() +
labs(title = "(2) Monthly Air Passengers (1949-1960)", x = "Year", y = "Passengers") +
theme_minimal()

ggplot(passengers_tb2, aes(x = date, y = value)) +
geom_line() +
labs(title = "(3) Monthly Air Passengers (1949-1960)", x = "Year", y = "Passengers") +
theme_minimal()

If you look at str(passengers_tb1) you'll see that the value column is a time series object. A simple way to avoid the (harmless?) error message is to change y = value to y = as.numeric(value).

Yes, ithe harmless error message disappears once I coerce variable value to as.numeric(value). Thanks a lot for your help. It clears my doubt over the problem. Thanks again.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.