Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Commit

Permalink
Provide appropriate access to grouping columns for ts_plot() (#727)
Browse files Browse the repository at this point in the history
Co-authored-by: Lluís <[email protected]>
  • Loading branch information
bensoltoff and llrs authored Aug 14, 2022
1 parent 155f1c6 commit 4462710
Show file tree
Hide file tree
Showing 3 changed files with 1,695 additions and 4 deletions.
6 changes: 4 additions & 2 deletions R/ts_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ ts_plot_ <- function(data, by = "days", trim = 0L, tz ="UTC", ...) {
data <- ts_data(data, by, trim, tz)
check_installed("ggplot2")
if (ncol(data) == 3L) {
# retrieve group name
ggplot2::ggplot(
data, ggplot2::aes(
x = .data[["time"]], y = .data[["n"]], colour = names(.data)[3])
x = .data[["time"]], y = .data[["n"]], colour = .data[[names(data)[3]]])
) +
ggplot2::geom_line(...)
} else if (ncol(data) == 4L) {
# retrieve group names
ggplot2::ggplot(
data, ggplot2::aes(
x = .data[["time"]], y = .data[["n"]], colour = names(.data)[3], linetype = names(.data)[4])
x = .data[["time"]], y = .data[["n"]], colour = .data[[names(data)[3]]], linetype = .data[[names(data)[4]]])
) +
ggplot2::geom_line(...)
} else {
Expand Down
Loading

0 comments on commit 4462710

Please sign in to comment.