-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename class. Fixes stars conversin bug. Improves plot fucntion.
- Loading branch information
Showing
11 changed files
with
110 additions
and
99 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,48 @@ | ||
#' Plot Patterns from twdtw-knn1 model | ||
#' | ||
#' This function visualizes time series patterns from the \code{"twdtw_knn1"} model. | ||
#' It produces a multi-faceted plot, where each facet represents a different time series | ||
#' label from the model's data. Within each facet, different bands or indices (attributes) | ||
#' are plotted as distinct lines, differentiated by color. | ||
#' | ||
#' @param x A model of class \code{"twdtw_knn1"}. | ||
#' | ||
#' @param bands A character vector specifying the bands or indices to plot. | ||
#' If NULL (default), all available bands or indices in the data will be plotted. | ||
#' | ||
#' @param ... Additional arguments passed to \code{\link[ggplot2]{ggplot}}. Currently not used. | ||
#' | ||
#' @return A \code{\link[ggplot2]{ggplot}} object displaying the time series patterns. | ||
#' | ||
#' @seealso twdtw_knn1 | ||
#' | ||
#' @inherit twdtw_knn1 examples | ||
#' | ||
#' @export | ||
plot.twdtw_knn1 <- function(x, bands = NULL, ...) { | ||
|
||
# Convert the list of time series data into a long-format data.frame | ||
df <- x$data | ||
df$id <- 1:nrow(df) | ||
df <- unnest(df, cols = 'observations') | ||
|
||
# Select bands | ||
if(!is.null(bands)){ | ||
df <- df[c('id', 'time', 'label', bands)] | ||
} | ||
|
||
# Pivote data into long format for ggplot2 | ||
df <- pivot_longer(df, !c('id', 'label', 'time'), names_to = "band", values_to = "value") | ||
|
||
# Construct the ggplot | ||
gp <- ggplot(df, aes(x = .data$time, y = .data$value, colour = .data$band, group = interaction(.data$id, .data$band))) + | ||
geom_line() + | ||
facet_wrap(~label) + | ||
theme(legend.position = "bottom") + | ||
guides(colour = guide_legend(title = "Bands")) + | ||
ylab("Value") + | ||
xlab("Time") | ||
|
||
return(gp) | ||
|
||
} |
This file was deleted.
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
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
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.