Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #' @importFrom ggplot2 autoplot
- #' @export
- ggplot2::autoplot
- new_mc_sum <- function(x, ...){
- tibble::new_tibble(x, subclass = "mc_sum")
- }
- autoplot.mc_sum <- function(object, ...){
- # defensive code to make sure people have ggplot2 installed
- if (!requireNamespace("ggplot2", quietly = TRUE)) {
- stop("ggplot2 is needed for this function to work. Install it via install.packages(\"ggplot2\")", call. = FALSE)
- }
- # check that the object is what you expect
- else if (!inherits(object, "mc_sum")) {
- stop("autoplot.mc_sum requires an mc_sum object, use object=object")
- }
- # plotting code
- ggplot2::ggplot(object,
- ggplot2::aes(x = case,
- y = n_miss)) +
- ggplot2::geom_col(width = 1,
- colour = "#484878", # lorikeet purple
- fill = "#484878") + # lorikeet purple
- ggplot2::coord_flip() +
- ggplot2::labs(y = "# Missing",
- x = "Cases") +
- ggplot2::theme_minimal() +
- ggplot2::scale_x_reverse()
- }
- fit <- lm(Ozone ~ ., airquality)
- fit
- summary(fit)
- summary(airquality)
- class(fit)
- class(airquality)
- miss_case_summary(airquality)
- autoplot(p1, type = "pairs")
- autoplot(p1, type = "points")
- miss_case_summary(airquality)
- gg_miss_case(airquality)
- miss_case_summary(airquality) %>%
- autoplot() +
- ggplot2::labs(title = "my title",
- x = "new_x",
- y = "new_y",
- subtitle = "my new subtitle")
- ##
- detect_outliers(data) # returns data of class "stream_outlier"
- detect_outliers(data) %>% autoplot(type = "ts")
- detect_outliers(data) %>% extract_data_ts()
- detect_outliers(data) %>% autoplot(type = "hd")
- detect_outliers(data) %>% extract_data_hd()
- #
- new_odd_data <- function(x){
- structure(x,
- class = c("odd_water_data", class(x)))
- }
- detect_water_outlier <- function(x){
- # magical oddstream detection happens here
- # odd_data <- odd_water_stream(x)
- return(new_odd_data(odd_data))
- }
- autoplot.whatever_class
- autoplot.odd_water_data <- function(object,
- type = "ts",
- title,
- ...){
- if (type == "ts") {
- # extract_data_ts is a function to get the data out of the plot.
- extract_data_ts(object) %>%
- ggplot2::ggplot(aes(x)) +
- ggplot2::labs(title = title)
- # the rest of your ggplot2 code
- }
- if (type == "hd") {
- }
- }
- detect_outliers(data)
Add Comment
Please, Sign In to add comment