Skip to content

Commit

Permalink
Merge pull request #87 from ldecicco-USGS/main
Browse files Browse the repository at this point in the history
Fix colors
  • Loading branch information
ldecicco-USGS authored May 16, 2024
2 parents 81c7fb8 + b55c213 commit e1d6ce2
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 62 deletions.
62 changes: 37 additions & 25 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/rocker/geospatial@sha256:d09a38602a306da8ac3e90beed95cf0b30e0f69aca1432379e65e62de9a4db3e

workflow:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH

stages:
- getready
- build
- check
- test
- end
Expand All @@ -25,55 +28,62 @@ variables:
GITHUB_PAT: $GITHUB_PAT
PAGES_OUTDIR: "$CI_PROJECT_DIR/public"

cache:
key: ${CI_JOB_NAME}
paths:
- $R_LIBS_USER

getready:
stage: getready
build-image:
stage: build
image: ${DEVOPS_REGISTRY}usgs/docker:20
services:
- name: ${DEVOPS_REGISTRY}usgs/docker:20-dind
alias: docker
rules:
- changes:
- docker/Dockerfile
- .gitlab-ci.yml
script:
- mkdir -p $R_LIBS_USER
- mkdir -p $APT_CACHE
- echo "options(Ncpus=$(nproc --all), repos=c(CRAN='$CRAN'))" >> $R_PROFILE
- Rscript -e "install.packages(c('devtools','pkgdown', 'connectapi', 'vctrs'))"
cache:
paths:
- $R_LIBS_USER
artifacts:
paths:
- $R_LIBS_USER
- echo ${CI_REGISTRY_PASSWORD} | docker login -u ${CI_REGISTRY_USER} --password-stdin $CI_REGISTRY
- docker pull ${CI_REGISTRY_IMAGE}:latest || true
- cd docker
- docker build
-t ${CI_REGISTRY_IMAGE}:BUILD_${CI_COMMIT_SHORT_SHA}
-t ${CI_REGISTRY_IMAGE}:latest
.
# If this is building a git tag, create the corresponding docker tag
- if [ -n "${CI_COMMIT_TAG}" ]; then docker tag ${CI_REGISTRY_IMAGE}:BUILD_${CI_COMMIT_SHORT_SHA} ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}; fi
- docker push --all-tags ${CI_REGISTRY_IMAGE}

buildcheck:
stage: check
image: ${CI_REGISTRY_IMAGE}:latest
dependencies:
- build-image
script:
- mkdir -p $BUILD_LOGS_DIR
- apt-get update
- apt-get -o dir::cache::archives=${APT_CACHE} install -y --no-install-recommends qpdf pandoc pandoc-citeproc
- R CMD build . --no-build-vignettes --no-manual
- R -e 'devtools::check(document = FALSE, args = "--no-tests", error_on = "error", check_dir = Sys.getenv("BUILD_LOGS_DIR"))'
artifacts:
expire_in: 1 week
paths:
- $BUILD_LOGS_DIR

unittests:
stage: test
image: ${CI_REGISTRY_IMAGE}:latest
dependencies:
- getready
- build-image
- buildcheck
script:
- R -e 'library(testthat); options(testthat.output_file = file.path(Sys.getenv("CI_PROJECT_DIR"), "test-out.xml")); devtools::test(reporter = "junit")'
artifacts:
when: always
expire_in: 1 week
paths:
- test-out.xml
reports:
junit: test-out.xml

covertests:
stage: test
image: ${CI_REGISTRY_IMAGE}:latest
dependencies:
- getready
- build-image
- buildcheck
script:
- R -e 'x <- covr::package_coverage(); covr::to_cobertura(x); x; '
Expand All @@ -82,10 +92,12 @@ covertests:
coverage_report:
coverage_format: cobertura
path: cobertura.xml
expire_in: 1 week
coverage: '/Coverage: \d+.\d+\%/'

pages:
stage: end
image: ${CI_REGISTRY_IMAGE}:latest
only:
- main
script:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: HASP
Type: Package
Title: Hydrologic AnalySis Package
Version: 1.0.2
Version: 1.0.3
Authors@R: c(person("Laura", "DeCicco",
role = c("aut", "cre"),
email = "[email protected]",
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
HASP 1.0.3
===========
* Fix some color options in monthly plot

HASP 1.0.2
===========
* Minor bug fix that happens in the first week of the year
Expand Down
72 changes: 42 additions & 30 deletions R/frequency_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ stats_by_interval <- function(interval,
#' plot_title = "L2701 Groundwater Level",
#' flip = TRUE,
#' percentile_colors = c(
#' "#d7191c",
#' "#fdae61",
#' "#ffffbf",
#' "#abdda4",
#' "#2b83ba"
#' "red",
#' "yellow",
#' "green",
#' "blue",
#' "orange"
#' ))
#'
#' monthly_frequency_custom_colors
Expand All @@ -288,7 +288,7 @@ stats_by_interval <- function(interval,
#' parameter_cd = "62610",
#' y_axis_label = label,
#' plot_title = "L2701 Groundwater Level",
#' flip = TRUE,
#' flip = FALSE,
#' include_edges = TRUE)
#' monthly_frequency_edge_bins
#'
Expand Down Expand Up @@ -381,13 +381,26 @@ monthly_frequency_plot <- function(gw_level_dv,
c("p75", "p90"), c("p90", "p95"))
groups <- c("5 - 10", "10 - 25", "25 - 75", "75 - 90", "90 - 95")
# define default colors
color_list <- c("firebrick3", "orange2", "green2", "steelblue1", "blue")
# set plot colors and markers
rectangle_colors <- c("5 - 10" = color_list[1],
"10 - 25" = color_list[2],
"25 - 75" = color_list[3],
"75 - 90" = color_list[4],
"90 - 95" = color_list[5])

color_list <- c("darkred", "orange2", "green2", "steelblue1", "blue")

if(include_edges){
color_list <- c("firebrick3", color_list, "darkblue")
}

# custom colors and shapes
if (length(percentile_colors) >= 5) {
color_list <- percentile_colors
} else if (is.na(percentile_colors) == FALSE) {
warning(
paste0(
"percentile_colors argument was provided but was invalid,",
" should be a vector of length 5 or 7 in which each item in",
" the vector represents a color."
)
)
}

# set scale breaks
scale_breaks <- c("90 - 95",
"75 - 90",
Expand All @@ -408,16 +421,27 @@ monthly_frequency_plot <- function(gw_level_dv,
cols <- append(cols, list(c("p95", "maxMed")))
groups <- c("0 - 5", groups, "95 - 100")
# expand color list
color_list <- c("darkred", color_list, "darkblue")

# expand rectangle colors
rectangle_colors <- c("0 - 5" = color_list[1],
rectangle_colors,
"5 - 10" = color_list[2],
"10 - 25" = color_list[3],
"25 - 75" = color_list[4],
"75 - 90" = color_list[5],
"90 - 95" = color_list[6],
"95 - 100" = color_list[7])
# expand the scale breaks
scale_breaks <- c("95 - 100",
scale_breaks,
"0 - 5")
}
} else {
# set plot colors and markers
rectangle_colors <- c("5 - 10" = color_list[1],
"10 - 25" = color_list[2],
"25 - 75" = color_list[3],
"75 - 90" = color_list[4],
"90 - 95" = color_list[5])
}

plot_list <- data.frame()

Expand Down Expand Up @@ -460,19 +484,6 @@ monthly_frequency_plot <- function(gw_level_dv,
points_plot)
}

# custom colors and shapes
if (length(percentile_colors) >= 5) {
color_list <- percentile_colors
} else if (is.na(percentile_colors) == FALSE) {
warning(
paste0(
"percentile_colors argument was provided but was invalid,",
" should be a vector of length 5 or 7 in which each item in",
" the vector represents a color."
)
)
}

point_shapes <- c("Monthly median" = 17,
"Data point" = 18)
point_colors <- c("Monthly median" = "black",
Expand Down Expand Up @@ -508,7 +519,8 @@ monthly_frequency_plot <- function(gw_level_dv,
x = month,
y = value,
shape = group,
color = group
color = group,
size = group
))
}

Expand Down
38 changes: 38 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM code.chs.usgs.gov:5001/ctek/docker/r-lang/r-base:4.4

# Necessary R libraries
RUN apt-get update -qq && apt-get -y --no-install-recommends install \
r-cran-dataretrieval \
r-cran-devtools \
r-cran-connectapi \
r-cran-covr \
r-cran-tidyverse \
r-cran-ggpp \
r-cran-scales \
r-cran-ggpmisc \
r-cran-checkmate \
r-cran-whisker \
r-cran-xfun \
r-cran-usethis \
r-cran-envstats \
r-cran-readxl \
r-cran-shiny \
r-cran-shinycssloaders \
r-cran-shinydashboard \
r-cran-shinyace \
r-cran-openxlsx \
r-cran-oce \
r-cran-kableextra \
r-cran-dt \
r-cran-leaflet \
r-cran-rkt \
r-cran-zyp \
r-cran-plotly \
r-cran-rlang \
r-cran-knitr \
r-cran-waterdata \
r-cran-rsconnect \
&& rm -rf /var/lib/apt/lists/*



12 changes: 6 additions & 6 deletions man/monthly_frequency_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e1d6ce2

Please sign in to comment.