From 096484fd03bd8d0350e16fcddf7c0295068711d5 Mon Sep 17 00:00:00 2001 From: "Pedro R. Andrade" Date: Wed, 31 May 2023 23:11:40 -0300 Subject: [PATCH 1/2] New argument year_grid to plot.patterns() --- R/sits_plot.R | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/R/sits_plot.R b/R/sits_plot.R index 268650b7d..c0f796433 100644 --- a/R/sits_plot.R +++ b/R/sits_plot.R @@ -367,6 +367,8 @@ plot.sits <- function(x, y, ..., together = FALSE) { #' @param y Ignored. #' @param ... Further specifications for \link{plot}. #' @param bands Bands to be viewed (optional). +#' @param year_grid Plot a grid of panels with labels representing +#' columns and years representing rows. Default is FALSE. #' @return A plot object produced by ggplot2 #' with one average pattern per label. #' @@ -381,7 +383,7 @@ plot.sits <- function(x, y, ..., together = FALSE) { #' } #' @export #' -plot.patterns <- function(x, y, ..., bands = NULL) { +plot.patterns <- function(x, y, ..., bands = NULL, year_grid = FALSE) { stopifnot(missing(y)) # verifies if scales package is installed .check_require_packages("scales") @@ -409,14 +411,25 @@ plot.patterns <- function(x, y, ..., bands = NULL) { plot.df <- tidyr::pivot_longer(plot.df, cols = sits_bands(x)) + if(year_grid) + plot.df <- plot.df %>% + dplyr::mutate(year = format(Time, format="%Y")) %>% + dplyr::mutate(Time = as.Date(format(Time, format="2000-%m-%d"))) + # Plot temporal patterns gp <- ggplot2::ggplot(plot.df, ggplot2::aes( x = .data[["Time"]], y = .data[["value"]], colour = .data[["name"]] )) + - ggplot2::geom_line() + - ggplot2::facet_wrap(~Pattern) + + ggplot2::geom_line() + + if(year_grid) + gp <- gp + ggplot2::facet_grid(year ~ Pattern) + else + gp <- gp + ggplot2::facet_wrap(~Pattern) + + gp <- gp + ggplot2::theme(legend.position = "bottom") + ggplot2::scale_x_date(labels = scales::date_format("%b")) + ggplot2::guides(colour = ggplot2::guide_legend(title = "Bands")) + From 7fdff5ce8fe05f8ac16e6ac7180cd7faa74c4123 Mon Sep 17 00:00:00 2001 From: "Pedro R. Andrade" Date: Thu, 1 Jun 2023 08:33:27 -0300 Subject: [PATCH 2/2] Small fix. --- R/sits_plot.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/sits_plot.R b/R/sits_plot.R index c0f796433..f385f914b 100644 --- a/R/sits_plot.R +++ b/R/sits_plot.R @@ -367,8 +367,8 @@ plot.sits <- function(x, y, ..., together = FALSE) { #' @param y Ignored. #' @param ... Further specifications for \link{plot}. #' @param bands Bands to be viewed (optional). -#' @param year_grid Plot a grid of panels with labels representing -#' columns and years representing rows. Default is FALSE. +#' @param year_grid Plot a grid of panels using labels as columns and +#' years as rows. Default is FALSE. #' @return A plot object produced by ggplot2 #' with one average pattern per label. #'