diff --git a/DESCRIPTION b/DESCRIPTION index 2a64e51..0c3ad10 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,9 +23,10 @@ Imports: dplyr, rmarkdown, forcats, tidyr, - htmltools + htmltools, + ggExtra Depends: - R (>= 2.10) + R (>= 3.5) Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index cd4e171..f074992 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,3 +22,4 @@ import(scales) import(sf) import(stringr) import(tidyr) +importFrom(ggExtra,ggMarginal) diff --git a/R/logged_depths.R b/R/logged_depths.R index 263760c..e78e375 100644 --- a/R/logged_depths.R +++ b/R/logged_depths.R @@ -13,6 +13,7 @@ #' @import dplyr #' @import scales #' @import sf +#' @importFrom ggExtra ggMarginal #' #' @return Returns a boxplot. #' @@ -30,27 +31,29 @@ logged_depths <- function (path = getwd()){ # The problem of making the previous function is that scuba_map does not get generated # Plot date against max depths https://www.neonscience.org/dc-time-series-plot-ggplot-r - ggplot(scuba_map %>% filter (!is.na(maximumDepthInMeters)), - aes(x = as.Date(eventDate), y = -as.numeric(maximumDepthInMeters), - fill = -as.numeric(maximumDepthInMeters))) + - geom_jitter (size = 5, alpha = 0.7, shape = 21, width = 5) + # Increase width for more explicit visualization, although it compromises it the veracity of the data - # theme_classic() + - # scale_color_economist () + - # geom_rangeframe() + - # theme_tufte() + - ggtitle("Dives depth") + - labs(fill = "Max Depth (metres)", - x = "Date", - y = "") + # I hide the y axis label because it is already specified in the color legend - - # Format dates in axis labels and date ticks - scale_x_date(breaks=date_breaks("12 months"), - labels=date_format("%Y")) + - theme(axis.text.x = element_text(angle = 45, hjust = 1)) + - - - geom_hline(yintercept = c(0, -20, -40), linetype = c("dotdash", "dashed", "solid"), - color = c("darkgrey", "deepskyblue4", "red"), size = 0.5, alpha = 0.6) + p <- ggplot(scuba_map %>% filter (!is.na(maximumDepthInMeters)), + aes(x = as.Date(eventDate), y = -as.numeric(maximumDepthInMeters), + fill = -as.numeric(maximumDepthInMeters))) + + geom_jitter (size = 5, alpha = 0.7, shape = 21, width = 5) + # Increase width for more explicit visualization, although it compromises it the veracity of the data + # theme_classic() + + # scale_color_economist () + + # geom_rangeframe() + + # theme_tufte() + + ggtitle("Dives depth") + + labs(fill = "Max Depth (metres)", + x = "Date", + y = "") + # I hide the y axis label because it is already specified in the color legend + + # Format dates in axis labels and date ticks + scale_x_date(breaks=date_breaks("12 months"), + labels=date_format("%Y")) + + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + + + + geom_hline(yintercept = c(0, -20, -40), linetype = c("dotdash", "dashed", "solid"), + color = c("darkgrey", "deepskyblue4", "red"), size = 0.5, alpha = 0.6) + ggMarginal(p, type="densigram", fill = "dodgerblue3", size = 9, alpha = 0.5) + }