Guest User

Untitled

a guest
Aug 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #' @importFrom ggplot2 autoplot
  2. #' @export
  3. ggplot2::autoplot
  4.  
  5. new_mc_sum <- function(x, ...){
  6. tibble::new_tibble(x, subclass = "mc_sum")
  7. }
  8.  
  9. autoplot.mc_sum <- function(object, ...){
  10.  
  11. # defensive code to make sure people have ggplot2 installed
  12. if (!requireNamespace("ggplot2", quietly = TRUE)) {
  13. stop("ggplot2 is needed for this function to work. Install it via install.packages(\"ggplot2\")", call. = FALSE)
  14. }
  15.  
  16. # check that the object is what you expect
  17. else if (!inherits(object, "mc_sum")) {
  18. stop("autoplot.mc_sum requires an mc_sum object, use object=object")
  19. }
  20.  
  21. # plotting code
  22. ggplot2::ggplot(object,
  23. ggplot2::aes(x = case,
  24. y = n_miss)) +
  25. ggplot2::geom_col(width = 1,
  26. colour = "#484878", # lorikeet purple
  27. fill = "#484878") + # lorikeet purple
  28. ggplot2::coord_flip() +
  29. ggplot2::labs(y = "# Missing",
  30. x = "Cases") +
  31. ggplot2::theme_minimal() +
  32. ggplot2::scale_x_reverse()
  33.  
  34. }
  35.  
  36. fit <- lm(Ozone ~ ., airquality)
  37. fit
  38. summary(fit)
  39. summary(airquality)
  40.  
  41. class(fit)
  42. class(airquality)
  43.  
  44.  
  45. miss_case_summary(airquality)
  46.  
  47. autoplot(p1, type = "pairs")
  48. autoplot(p1, type = "points")
  49.  
  50. miss_case_summary(airquality)
  51.  
  52. gg_miss_case(airquality)
  53.  
  54. miss_case_summary(airquality) %>%
  55. autoplot() +
  56. ggplot2::labs(title = "my title",
  57. x = "new_x",
  58. y = "new_y",
  59. subtitle = "my new subtitle")
  60.  
  61. ##
  62.  
  63. detect_outliers(data) # returns data of class "stream_outlier"
  64.  
  65. detect_outliers(data) %>% autoplot(type = "ts")
  66.  
  67. detect_outliers(data) %>% extract_data_ts()
  68.  
  69. detect_outliers(data) %>% autoplot(type = "hd")
  70.  
  71. detect_outliers(data) %>% extract_data_hd()
  72.  
  73. #
  74.  
  75. new_odd_data <- function(x){
  76. structure(x,
  77. class = c("odd_water_data", class(x)))
  78. }
  79.  
  80. detect_water_outlier <- function(x){
  81.  
  82. # magical oddstream detection happens here
  83.  
  84. # odd_data <- odd_water_stream(x)
  85. return(new_odd_data(odd_data))
  86. }
  87.  
  88.  
  89. autoplot.whatever_class
  90.  
  91. autoplot.odd_water_data <- function(object,
  92. type = "ts",
  93. title,
  94. ...){
  95.  
  96. if (type == "ts") {
  97. # extract_data_ts is a function to get the data out of the plot.
  98. extract_data_ts(object) %>%
  99. ggplot2::ggplot(aes(x)) +
  100. ggplot2::labs(title = title)
  101. # the rest of your ggplot2 code
  102.  
  103. }
  104.  
  105. if (type == "hd") {
  106.  
  107. }
  108.  
  109. }
  110.  
  111.  
  112. detect_outliers(data)
Add Comment
Please, Sign In to add comment