FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added fable/feast support by moutikabdessabour · Pull Request #2045 · plotly/plotly.R · GitHub

Added fable/feast support - #2045

Open
moutikabdessabour wants to merge 3 commits into
plotly:masterfrom
moutikabdessabour:add_fable_support
Open

Added fable/feast support#2045
moutikabdessabour wants to merge 3 commits into
plotly:masterfrom
moutikabdessabour:add_fable_support

Conversation

moutikabdessabour commented Oct 13, 2021
edited by cpsievert
Loading

Copy link
Copy Markdown
Contributor

Implemented to_basic methods that handle the output of fabletools:autoplot.fbl_ts and Added tests

library(dplyr)
library(forecast)
library(tsibble)

data <- tourism %>%
    filter(Region == "Melbourne") %>%
    `[`(, c("Quarter", "Trips", "Region")) %>%
    distinct(Quarter, .keep_all = TRUE) %>%
    as_tsibble(key = Region) 
p <- data %>%
    model(
        ets = ETS(Trips ~ trend("A")),
    ) %>%
    forecast(h = "5 years") %>%
    autoplot(data)

p

ggplotly(p)


.

Comment thread R/layers2traces.R
Comment on lines +648 to +650
to_basic.data.frame <- function(data, prestats_data, layout, params, p, ...) {
prefix_class(data, "GeomPath")
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hmm, this doesn't seem right, do you have an example where this becomes relevant?

moutikabdessabour Nov 2, 2021
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this is actually a trick because the autoplot returns only a data.frame and GeomHilo... this results in only drawing the predictions without the line.

Comment thread R/layers2traces.R
Comment on lines +620 to +641
transform_hiloribbon <- function(data) {
data <- data[order(data$x), ]
data$hilo <- NULL

data$x_plotlyDomain <- as.character(data$x_plotlyDomain)

maximum_lev <- max(data$level) + 1

data$alpha <- (maximum_lev * (maximum_lev - data$level) - 1 )/ maximum_lev**3
data$colour <- data$alpha

unused_aes <- ! names(data) %in% c("x", "y", "ymin", "ymax")

row_number <- nrow(data)

data_rev <- data[row_number:1L, ]
structure(rbind(
cbind(x = data$x, y = data$ymin, data[unused_aes]),
cbind(x = data$x[row_number], y = data$ymin[row_number], data[row_number, unused_aes]),
cbind(x = data_rev$x, y = data_rev$ymax, data_rev[unused_aes])
), class = class(data))
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Come to think of it, I think most of this as well as to_basic.GeomAlluvium() could be replaced by ribbon_dat()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It's the same code with minor changes.

Copy link
Copy Markdown
Collaborator

@danton267 would you mind filing an issue to request this feature so that it should up in this list of issues? https://github.com/plotly/plotly.R/issues/created_by/danton267

cpsievert mentioned this pull request Nov 2, 2021
27 tasks

Copy link
Copy Markdown
Collaborator

@moutikabdessabour what package is the model() function from in your example?

Copy link
Copy Markdown
Collaborator

@moutikabdessabour if we're going to add support for {fable}/{feasts}, we should try our best to cover anything that one could create via forecast::forecast() + autoplot(), which would at least include forecast::GeomForecast

Copy link
Copy Markdown
Contributor Author

@cpsievert Ok I will work on it.

Copy link
Copy Markdown
Contributor Author

@cpsievert The model function is exported from the {fabletools} package

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL