Skip to content

Commit

Permalink
added densigram to logged depths plot
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenpp7 committed Mar 7, 2021
1 parent e36ac10 commit 56bf019
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ import(scales)
import(sf)
import(stringr)
import(tidyr)
importFrom(ggExtra,ggMarginal)
45 changes: 24 additions & 21 deletions R/logged_depths.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#' @import dplyr
#' @import scales
#' @import sf
#' @importFrom ggExtra ggMarginal
#'
#' @return Returns a boxplot.
#'
Expand All @@ -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)

}

0 comments on commit 56bf019

Please sign in to comment.