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

Create function for ts_qq_plot() #181

Closed
spsanderson opened this issue Dec 10, 2021 · 0 comments
Closed

Create function for ts_qq_plot() #181

spsanderson opened this issue Dec 10, 2021 · 0 comments
Assignees
Labels

Comments

@spsanderson
Copy link
Owner

ts_qq_plot <- function(.calibration_tbl, .model_id = NULL
                              , .interactive = FALSE){
  
  # * Tidyeval ----
  calibration_tbl  <- .calibration_tbl
  model_id         <- .model_id
  interactive_bool <- .interactive
  
  # * Checks ----
  if(!modeltime::is_calibrated(calibration_tbl)){
    stop(call. = FALSE, "You must supply a calibrated modeltime table.")
  }
  
  # Calibration Tibble filter
  if(is.null(model_id)){
    calibration_tbl <- calibration_tbl
  } else {
    calibration_tbl <- calibration_tbl %>%
      dplyr::filter(.model_id == model_id)
  }
  
  g <- calibration_tbl %>% 
    dplyr::ungroup() %>% 
    dplyr::select(-.model, -.type) %>% 
    tidyr::unnest(.calibration_data) %>% 
    ggplot2::ggplot(
      mapping = ggplot2::aes(
        sample = .residuals
        , fill = .model_desc
      )
    ) + 
    ggplot2::stat_qq() +
    ggplot2::stat_qq_line() +
    ggplot2::facet_wrap(
      ~ .model_desc
      , scales = "free"
    ) + 
    tidyquant::scale_color_tq() + 
    ggplot2::theme_minimal() +
    ggplot2::theme(legend.position = "none") +
    ggplot2::labs(
      title = "QQ Scatter Plot"
      , x = "Theoretical Quantiles"
      , y = "Sample Quantiles"
    )
  
  if(interactive_bool){
    g <- plotly::ggplotly(g)
  }
  
  return(g)
  
}
@spsanderson spsanderson added this to the healthyR.ts 0.1.7 milestone Dec 10, 2021
@spsanderson spsanderson self-assigned this Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant