-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ssi-dk:telkamp7/issue12
Telkamp7/issue12
- Loading branch information
Showing
7 changed files
with
266 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#' Create a complete ggplot appropriate to a particular data type | ||
#' | ||
#' @description | ||
#' `r lifecycle::badge("experimental")` | ||
#' | ||
#' This function generates a complete ggplot object suitable for | ||
#' visualizing time series data in an `aedseo_tsd` object. It creates a line | ||
#' plot connecting the observations and adds points at each data point. | ||
#' | ||
#' @param object An `aedseo_tsd` or `aedseo` object | ||
#' @param linewidth Numeric, the width of the line for the growth rate | ||
#' @param alpha Numeric, the alpha (transparency) for the confidence interval | ||
#' ribbon | ||
#' @param ... Additional arguments (not used). | ||
#' | ||
#' @return A ggplot object for visualizing the time series data. | ||
#' | ||
#' @aliases autoplot | ||
#' | ||
#' @examples | ||
#' # Create an example aedseo_tsd object | ||
#' aedseo_tsd_object <- tsd( | ||
#' observed = c(100, 120, 150, 180, 220, 270), | ||
#' time = as.Date(c( | ||
#' "2023-01-01", | ||
#' "2023-01-02", | ||
#' "2023-01-03", | ||
#' "2023-01-04", | ||
#' "2023-01-05", | ||
#' "2023-01-06" | ||
#' )), | ||
#' time_interval = "day" | ||
#' ) | ||
#' | ||
#' # Create a ggplot visualization for the aedseo_tsd object | ||
#' # autoplot(aedseo_tsd_object) | ||
#' | ||
#' # Create an aedseo object | ||
#' aedseo_object <- aedseo( | ||
#' tsd = aedseo_tsd_object, | ||
#' k = 3, | ||
#' level = 0.95, | ||
#' family = "quasipoisson" | ||
#' ) | ||
#' | ||
#' # Create a ggplot visualization of growth rates with confidence intervals | ||
#' # autoplot(aedseo_object, linewidth = 1, alpha = 0.2) | ||
#' @importFrom ggplot2 autoplot | ||
#' @rdname autoplot | ||
#' @method autoplot aedseo_tsd | ||
#' @export | ||
autoplot.aedseo_tsd <- function(object, ...) { | ||
object %>% | ||
ggplot2::ggplot( | ||
mapping = ggplot2::aes( | ||
x = .data$time, | ||
y = .data$observed | ||
) | ||
) + | ||
ggplot2::geom_point() + | ||
ggplot2::geom_line() | ||
} | ||
#' @rdname autoplot | ||
#' @method autoplot aedseo | ||
#' @export | ||
autoplot.aedseo <- function(object, linewidth = 0.7, alpha = 0.3, ...) { | ||
object %>% | ||
ggplot2::ggplot( | ||
mapping = ggplot2::aes( | ||
x = .data$reference_time, | ||
y = .data$growth_rate, | ||
ymin = .data$lower_growth_rate, | ||
ymax = .data$upper_growth_rate | ||
) | ||
) + | ||
ggplot2::geom_line(linewidth = linewidth) + | ||
ggplot2::geom_ribbon(alpha = alpha) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#' Create a complete ggplot appropriate to a particular data type | ||
#' | ||
#' @description | ||
#' `r lifecycle::badge("experimental")` | ||
#' | ||
#' This function generates a complete ggplot object suitable for | ||
#' visualizing time series data in an `aedseo_tsd` object. It creates a line | ||
#' plot connecting the observations and adds points at each data point. | ||
#' | ||
#' @param x An `aedseo_tsd` or `aedseo` object | ||
#' @param ... Additional arguments passed to specific methods. | ||
#' | ||
#' @return A ggplot object for visualizing the time series data. | ||
#' | ||
#' @aliases plot | ||
#' | ||
#' @seealso [autoplot()] | ||
#' | ||
#' @examples | ||
#' # Create an example aedseo_tsd object | ||
#' aedseo_tsd_object <- tsd( | ||
#' observed = c(100, 120, 150, 180, 220, 270), | ||
#' time = as.Date(c( | ||
#' "2023-01-01", | ||
#' "2023-01-02", | ||
#' "2023-01-03", | ||
#' "2023-01-04", | ||
#' "2023-01-05", | ||
#' "2023-01-06" | ||
#' )), | ||
#' time_interval = "day" | ||
#' ) | ||
#' | ||
#' # Create a ggplot visualization for the aedseo_tsd object | ||
#' plot(aedseo_tsd_object) | ||
#' | ||
#' # Create an aedseo object | ||
#' aedseo_object <- aedseo( | ||
#' tsd = aedseo_tsd_object, | ||
#' k = 3, | ||
#' level = 0.95, | ||
#' family = "quasipoisson" | ||
#' ) | ||
#' | ||
#' # Create a ggplot visualization of growth rates with confidence intervals | ||
#' plot(aedseo_object, linewidth = 1, alpha = 0.2) | ||
#' @importFrom graphics plot | ||
#' @rdname plot | ||
#' @method plot aedseo_tsd | ||
#' @export | ||
plot.aedseo_tsd <- function(x, ...) { | ||
print(autoplot(x, ...)) | ||
} | ||
#' @rdname plot | ||
#' @method plot aedseo | ||
#' @export | ||
plot.aedseo <- function(x, ...) { | ||
print(autoplot(object = x, ...)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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