diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..83f28ed --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,11 @@ +^.*\.Rproj$ +^\.Rproj\.user$ +^kwb\.barplot\.Rproj$ +^LICENSE\.md$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ +^\.github$ +^codecov\.yml$ +^index\.md$ +^README\.md$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..510d6b4 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,82 @@ +on: + push: + branches: + - master + - main + - dev + pull_request: + branches: + - master + - main + - dev + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macOS-latest, r: 'release'} + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: windows-latest, r: 'devel'} + - {os: windows-latest, r: 'oldrel'} + - {os: windows-latest, r: 'release'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), "depends.Rds", version = 2) + shell: Rscript {0} + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-${{ matrix.config.r }}-3-${{ hashFiles('depends.Rds') }} + restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-3- + + - name: Install system dependencies + if: runner.os == 'Linux' + env: + RHUB_PLATFORM: linux-x86_64-ubuntu-gcc + run: | + Rscript -e "remotes::install_github('r-hub/sysreqs')" + sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))") + sudo -s eval "$sysreqs" + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} + + - name: Check + run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "warning", check_dir = "check") + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@master + with: + name: ${{ runner.os }}-r${{ matrix.config.r }}-results + path: check diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..58a9d79 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,49 @@ +on: + push: + branches: + - main + - master + - dev + +name: pkgdown + +jobs: + pkgdown: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + install.packages("pkgdown", type = "binary") + shell: Rscript {0} + + - name: Install package + run: R CMD INSTALL . + + - name: Deploy package + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml new file mode 100644 index 0000000..0d3cb71 --- /dev/null +++ b/.github/workflows/pr-commands.yaml @@ -0,0 +1,51 @@ +on: + issue_comment: + types: [created] +name: Commands +jobs: + document: + if: startsWith(github.event.comment.body, '/document') + name: document + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + - uses: r-lib/actions/pr-fetch@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - uses: r-lib/actions/setup-r@master + - name: Install dependencies + run: Rscript -e 'install.packages(c("remotes", "roxygen2"))' -e 'remotes::install_deps(dependencies = TRUE)' + - name: Document + run: Rscript -e 'roxygen2::roxygenise()' + - name: commit + run: | + git add man/\* NAMESPACE + git commit -m 'Document' + - uses: r-lib/actions/pr-push@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + style: + if: startsWith(github.event.comment.body, '/style') + name: style + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + - uses: r-lib/actions/pr-fetch@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - uses: r-lib/actions/setup-r@master + - name: Install dependencies + run: Rscript -e 'install.packages("styler")' + - name: Style + run: Rscript -e 'styler::style_pkg()' + - name: commit + run: | + git add \*.R + git commit -m 'Style' + - uses: r-lib/actions/pr-push@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..4efc7ab --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,48 @@ +on: + push: + branches: + - master + - main + pull_request: + branches: + - master + - main + +name: test-coverage + +jobs: + test-coverage: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install dependencies + run: | + install.packages(c("remotes")) + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("covr") + shell: Rscript {0} + + - name: Test coverage + run: covr::codecov() + shell: Rscript {0} diff --git a/.gitignore b/.gitignore index 5b6a065..234f028 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .Rhistory .RData .Ruserdata +docs diff --git a/DESCRIPTION b/DESCRIPTION index 464bdfe..ea8dc1d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,26 @@ Package: kwb.barplot -Maintainer: Hauke Sonnenberg -Author: Hauke Sonnenberg -Version: 0.2.0 -License: GPL -Title: Evaluation of MIA-CSO data with R +Title: Evaluation of MIA-CSO Data with R +Version: 0.3.0 +Authors@R: + c(person(given = "Hauke", + family = "Sonnenberg", + role = c("aut", "cre"), + email = "hauke.sonnenberg@kompetenz-wasser.de", + comment = c(ORCID = "0000-0001-9134-2871")), + person(given = "Michael", + family = "Rustler", + role = "ctb", + email = "michael.rustler@kompetenz-wasser.de", + comment = c(ORCID = "0000-0003-0647-7726")), + person(given = "Kompetenzzentrum Wasser Berlin gGmbH (KWB)", + role = "cph")) Description: Barplot function that can arrange bars along the x axis. +License: MIT + file LICENSE +URL: https://github.com/KWB-R/kwb.barplot +BugReports: https://github.com/KWB-R/kwb.barplot/issues +Encoding: UTF-8 +LazyData: true +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.1.2 +Suggests: + covr diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c56ada2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2014-2021 Kompetenzzentrum Wasser Berlin gGmbH (KWB) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3bb49fd --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2014-2021 Kompetenzzentrum Wasser Berlin gGmbH (KWB) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE index 42c40be..fc80f72 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1 +1,4 @@ -export(hsBarplot, hsBarplot2) +# Generated by roxygen2: do not edit by hand + +export(hsBarplot) +export(hsBarplot2) diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..2530577 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,9 @@ +# kwb.barplot 0.3.0 + +* Harmonise package with R package [kwb.pkgbuild](https://github.com/kwb-r/kwb.pkgbuild) + +* Added a `NEWS.md` file to track changes to the package. + +* see https://style.tidyverse.org/news.html for writing a good `NEWS.md` + + diff --git a/R/.setup_package.R b/R/.setup_package.R new file mode 100644 index 0000000..34e0912 --- /dev/null +++ b/R/.setup_package.R @@ -0,0 +1,38 @@ +### How to build an R package from scratch +remotes::install_github("kwb-r/kwb.pkgbuild") + +usethis::create_package(".") +fs::file_delete(path = "DESCRIPTION") + + +author <- list(name = "Hauke Sonnenberg", + orcid = "0000-0001-9134-2871", + url = "https://github.com/hsonne") + +pkg <- list(name = "kwb.barplot", + title = "Evaluation of MIA-CSO Data with R", + desc = paste("Barplot function that can arrange bars along the x axis.")) + + +kwb.pkgbuild::use_pkg(author, + pkg, + version = "0.3.0", + stage = "experimental") + + +usethis::use_vignette("tutorial") + +### R functions +if(FALSE) { + ## add your dependencies (-> updates: DESCRIPTION) + pkg_dependencies <- c('dygraphs', "kwb.event", "kwb.utils") + + sapply(pkg_dependencies, usethis::use_package) + + desc::desc_add_remotes("github::kwb-r/kwb.event",normalize = TRUE) + desc::desc_add_remotes("github::kwb-r/kwb.utils",normalize = TRUE) + + +} + +kwb.pkgbuild::create_empty_branch_ghpages(pkg$name) diff --git a/R/hsLibBarplot.R b/R/hsLibBarplot.R index 66e1c78..65e3b03 100644 --- a/R/hsLibBarplot.R +++ b/R/hsLibBarplot.R @@ -1,26 +1,29 @@ -# Created: 2011-12-07 -# Updated: 2012-08-31 - # hsBpDefaultXlim -------------------------------------------------------------- -hsBpDefaultXlim <- function -### hsBpDefaultXlim -( - position, barGroupWidth=1 -) + +#' Default xlim for Barplot +#' +#' @param position vector of x-positions of bars +#' @param barGroupWidth bargroup widths. Default: 1 +#' @return vector of numeric of length two +hsBpDefaultXlim <- function(position, barGroupWidth = 1) { - c(min(position)-max(barGroupWidth)/2, - max(position)+max(barGroupWidth)/2) + c(min(position) - max(barGroupWidth) / 2, + max(position) + max(barGroupWidth) / 2) } # hsBpGetXlim ------------------------------------------------------------------ -hsBpGetXlim <- function -### hsBpGetXlim -( - myData, - myWidth=1, - mySpace=NULL, - myBeside=FALSE -) + +#' xlim for Barplot +#' +#' Depending on the argument values that are passed to \code{barplot()} a good +#' vector to be used as xlim is returned. +#' +#' @param myData corresponding to "height" in \code{\link{barplot}} +#' @param myWidth corresponding to "width" in \code{\link{barplot}} +#' @param mySpace corresponding to "space" in \code{\link{barplot}} +#' @param myBeside corresponding to "beside" in \code{\link{barplot}} +#' @return vector of numeric of length two +hsBpGetXlim <- function(myData, myWidth = 1, mySpace = NULL, myBeside = FALSE) { # Get number of bar groups and number of bars per group Nn <- hsBpNumBars(myData, myBeside) @@ -36,15 +39,15 @@ hsBpGetXlim <- function mySpace = 0.2 } } - + # scaling factor sf <- mean(myWidth) print(paste("scaling factor:", sf)) - + # minimum is after first space mi <- mySpace[1] * sf - + # maximum is after N bar groups and N spaces s1 <- sum(rep(mySpace, length.out = N)) s2 <- sum(rep(myWidth, length.out = N)) @@ -54,84 +57,96 @@ hsBpGetXlim <- function } # hsBpBargroupWidth ------------------------------------------------------------ -hsBpBargroupWidth <- function -### hsBpBargroupWidth -( - myWidth, - myBarsPerGroup, - myInnerSpace -) -{ - # The widths given in w represent the widths of the bars in one group. - # The width W of the total bar group is calculated as - # W = sum of bar widths in group minus (n-1)*spi with n = number of bars - # per group and spi = inner space between bars in a bar group. +#' Width of Bargroup +#' +#' The widths represent the widths of the bars in one group. It is calculated +#' as: sum(myWidth) + (myBarsPerGroup - 1) * myInnerSpace +#' +#' @param myWidth widths of the bars in one group +#' @param myBarsPerGroup number of bars per group +#' @param myInnerSpace inner space between bars in a bar group +#' @return vector of numeric of length one +hsBpBargroupWidth <- function(myWidth, myBarsPerGroup, myInnerSpace) +{ # Make myWidth as long as needed if (length(myWidth) > myBarsPerGroup) { myWidth <- myWidth[1:myBarsPerGroup] # Shorten myWidth } else { # By multiplying with a vector of as many ones as there are bars per group - # we guarantee to calculate the correct sum of bar widths, even if the - # number of elements given in w does not correspond to the number of bars + # we guarantee to calculate the correct sum of bar widths, even if the + # number of elements given in w does not correspond to the number of bars # per group. myWidth <- myWidth*rep(1, myBarsPerGroup) # Enlarge myWidth } - + # Calculate the bar group width sum(myWidth) + (myBarsPerGroup-1)*myInnerSpace } # hsBpNumBars ------------------------------------------------------------------ -hsBpNumBars <- function -### Number of bar groups (N) and bars per group (n) produced by barplot() -### depending on given data and parameter "beside" -(myData, myBeside) { - if(is.matrix(myData)) { - if(myBeside) { - c(N=ncol(myData), n=nrow(myData)) - } - else { - c(N=ncol(myData)*nrow(myData), n=1) - } + +#' Number of Bar Groups and Bars Per Group Produced by barplot() +#' +#' Number of bar groups (N) and bars per group (n) produced by barplot(), +#' depending on given data and parameter "beside" +#' +#' @param myData as passed in \code{height} to \code{\link{barplot}} +#' @param myBeside as passed in \code{beside} to \code{\link{barplot}} +#' @return Returns tupel containing N = number of bar groups and n = number of +#' bars per group +#' +hsBpNumBars <- function(myData, myBeside) +{ + if (!is.matrix(myData)) { + return(c(N = length(myData), n = 1)) } - else { - c(N=length(myData), n=1) + + if (myBeside) { + + c(N = ncol(myData), n = nrow(myData)) + + } else { + + c(N = ncol(myData) * nrow(myData), n = 1) } -### Returns tupel containing N = number of bar groups and n = number of bars -### per group } # hsBpSpace -------------------------------------------------------------------- -hsBpSpace <- function -### Calculates the spaces between bars of widths w at positions x as -### difference between the x values minus half the width of the bars/bar groups. -( -myWidth, -### Bar widths. If bars are to be stacked (isp = NULL, see below) w represents -### the widths of the different (stacked) bars. If bars are to be arranged -### side by side (isp >= 0) w represents the widths of the bars within -### one and the same bar group. Corresponding bars of different groups will -### always have the same width. -position, -### X-positions of bars/bar groups -myXlim=NULL, -### Vector containing minimum and maximum x-value to be shown in the plot. -myBeside=FALSE, -### If TRUE, bars of a bar group are not stacked but arranged side by side. -### Then, myWidth contains the widths of the bars within one group. Otherwise -### (myBeside = FALSE) myWidth contains the widths of the (stacked) bars. -barsPerGroup=1, -### Number of bars per group. If this parameter is greater than 1, it means -### that bars are to be arranged side by side instead of stacked. -innerSpace=0, -### "Inner" space between bars of the same group (only used if bpg > 1). -dbg=FALSE -) { - # Calculation of the widths W of the bars/bar groups. + +#' Spaces Between Bars +#' +#' Calculates the spaces between bars of widths w at positions x as difference +#' between the x values minus half the width of the bars/bar groups. +#' +#' @param myWidth Bar widths. If bars are to be stacked (isp = NULL, see below) +#' w represents the widths of the different (stacked) bars. If bars are to be +#' arranged side by side (isp >= 0) w represents the widths of the bars within +#' one and the same bar group. Corresponding bars of different groups will +#' always have the same width. +#' @param position X-positions of bars/bar groups +#' @param myXlim Vector containing minimum and maximum x-value to be shown in +#' the plot. +#' @param myBeside If TRUE, bars of a bar group are not stacked but arranged +#' side by side. Then, \code{myWidth} contains the widths of the bars within +#' one group. Otherwise (\code{myBeside} = FALSE) \code{myWidth} contains the +#' widths of the (stacked) bars. +#' @param barsPerGroup Number of bars per group. If this parameter is greater +#' than 1, it means that bars are to be arranged side by side instead of +#' stacked. +#' @param innerSpace "Inner" space between bars of the same group (only used if +#' bpg > 1). +#' @param dbg whether to print debug messages or not +#' @return Returns a space vector as needed to be passed to the barplot function +#' +hsBpSpace <- function( + myWidth, position, myXlim = NULL, myBeside = FALSE, barsPerGroup = 1, + innerSpace = 0, dbg = FALSE +) { + # Calculation of the widths W of the bars/bar groups. # If bars are to be arranged side by side, the (constant) width W of a whole - # bar group is calculated. If bars are to be stacked, the width(s) W of the + # bar group is calculated. If bars are to be stacked, the width(s) W of the # bar groups are given in myWidth if(myBeside) { print("Calling hsBpBargroupWidth with:") @@ -143,104 +158,116 @@ dbg=FALSE else { W <- myWidth } - + if (dbg) { - print(paste("width(s) of bar group(s):", paste(W, collapse=",")), quote=FALSE) + print(paste("width(s) of bar group(s):", paste(W, collapse=",")), quote = FALSE) print(W) } - + # If no limits are given, set limits to minimal and maximal value if (is.null(myXlim)) { myXlim <- hsBpDefaultXlim(position, W) } if (dbg) { - print(paste("Limits:", paste(myXlim[1], myXlim[2], sep=",")), quote=FALSE) + print(paste("Limits:", paste(myXlim[1], myXlim[2], sep = ",")), quote = FALSE) } - + # Calculation of spaces between bars/bar groups. - s <- c((position-W/2), myXlim[2]) - c(myXlim[1], (position+W/2)) + s <- c((position-W/2), myXlim[2]) - c(myXlim[1], (position + W/2)) if (dbg) { print("all Spaces:", quote=FALSE) print(s) } - + # Cut-off the last element of the space vector since it is not needed by the # barplot function to be called. s <- s[1:(length(position))] - + if (dbg) { print("spaces without last:", quote=FALSE) print(s) } - - # If bars are arranged in goups and if the bars within one group shall be - # arranged side by side ("innner" space isp is given) then we have to - # prepare a new space vector s to be passed to R's barplot function. - # That vector not only contains the spaces between the bar groups but also + + # If bars are arranged in goups and if the bars within one group shall be + # arranged side by side ("innner" space isp is given) then we have to + # prepare a new space vector s to be passed to R's barplot function. + # That vector not only contains the spaces between the bar groups but also # the spaces between the bars within one group. # E.g. for 2 groups of 3 bars each: s = c(s1, s2, s3, s4, s5, s6) with - # s1: space before 1st bar of 1st group, - # s2: space between 1st and 2nd bar of 1st group, - # s3: space between 2nd and 3rd bar of 1st group, - # s4: space between 3rd bar of 1st group and 1st bar of 2nd group, - # s5: space between 1st and 2nd bar of 2nd group, - # s6: space between 2nd and 3rd bar of 2nd group. + # s1: space before 1st bar of 1st group, + # s2: space between 1st and 2nd bar of 1st group, + # s3: space between 2nd and 3rd bar of 1st group, + # s4: space between 3rd bar of 1st group and 1st bar of 2nd group, + # s5: space between 1st and 2nd bar of 2nd group, + # s6: space between 2nd and 3rd bar of 2nd group. if (myBeside) { n <- barsPerGroup # nrow(y) # number of bars per group N <- length(position) # ncol(y) # number of bar groups - - # Initialise a new vector with as many elements as there are bars in - # total (number of elements in the matrix y), giving each element the + + # Initialise a new vector with as many elements as there are bars in + # total (number of elements in the matrix y), giving each element the # value of the "inner" space isp. tmp <-rep(innerSpace, n*N) - + # Overwrite the elements at position 1+0*n, 1+1*n, 1+2*n, ... 1+(N-1)*n # with the spaces between the different bar groups. tmp[1+(0:(N-1))*n] <- s - + # Set the new space vector s <- tmp } # R's barplot function interprets the space values as multiples of the mean # bar width. However, we calculated the spaces in units of x. s/mean(myWidth) -### Returns a space vector as needed to be passed to the barplot function } # hsBarplot -------------------------------------------------------------------- -hsBarplot <- function -### Extended version of R barplot function, enabling x positioning of the bars. -( + +#' barplot() with X-Position Support +#' +#' Extended version of R barplot function, enabling x positioning of the bars. +#' +#' @param myHeight Vector or matrix containing the bar heights, see R's barplot +#' function. +#' @param myWidth Bar widths. If bars are to be stacked (isp = NULL, see below) +#' w represents the widths of the stacked bars. If bars shall be plotted side +#' by side instead of stacked (isp >= 0) w represents the widths of the bars +#' within one and the same bar group. Corresponding bars of different groups +#' will always have the same width. +#' @param myPosition Vector containing the x-positions of the bars/bar groups. +#' @param myXlim Vector containing minimum and maximum x-value to be shown in +#' the plot. +#' @param myBeside If TRUE, bars within a bar group are arranged side by side +#' instead of stacked. +#' @param myReverse If TRUE, the bars in the plot will reverted, i.e. they will +#' be arranged according to decreasing x-values. +#' @param myInnerSpace "Inner" space between bars of the same bar group (only +#' relevant if y is a matrix and not a vector). If NULL, bars of the same bar +#' group will be stacked +#' @param myAxis whether to draw an axis or not +#' @param dbg whether to print debug messages or not +#' @param myYlim ylim vector +#' @param myValLabs whether to put value labels on top of the bars +#' @param \dots further arguments passed to \code{\link{barplot}} +#' @export +#' @examples +#' hsBarplot(1:10, myWidth = 0.2, myPosition = 0.1 * c(1:10)^2) +hsBarplot <- function( myHeight, - ### Vector or matrix containing the bar heights, see R's barplot function. myWidth = 1, - ### Bar widths. If bars are to be stacked (isp = NULL, see below) w represents - ### the widths of the stacked bars. If bars shall be plotted side by side - ### instead of stacked (isp >= 0) w represents the widths of the bars within - ### one and the same bar group. Corresponding bars of different groups will - ### always have the same width. myPosition = NULL, - ### Vector containing the x-positions of the bars/bar groups. myXlim = NULL, - ### Vector containing minimum and maximum x-value to be shown in the plot. myBeside = FALSE, - ### If TRUE, bars within a bar group are arranged side by side instead of - ### stacked. - myReverse = FALSE, - ### If TRUE, the bars in the plot will reverted, i.e. they will be arranged - ### according to decreasing x-values. + myReverse = FALSE, myInnerSpace = 0, - ### "Inner" space between bars of the same bar group (only relevant if y is - ### a matrix and not a vector). If NULL, bars of the same bar group will be - ### stacked myAxis = TRUE, dbg = FALSE, myYlim = NULL, myValLabs = FALSE, ... -) +) { if (dbg) { cat("-------------------------------\n") @@ -255,13 +282,13 @@ hsBarplot <- function cat(sprintf("*** myInnerSpace: %f\n", myInnerSpace)) cat(sprintf("*** myAxis: %s\n", myAxis)) } - + # Init vector containing spaces mySpace <- NULL - + # If x positions of bars are given, calculate spaces and limits if (! is.null(myPosition)) { - + # Calculate the spaces between the bars/bar groups. if (is.null(nrow(myHeight))) { n <- 1 @@ -269,93 +296,93 @@ hsBarplot <- function else { n <- ifelse(myBeside, nrow(myHeight), 1) # number of bars per group } - + if (dbg) { print(paste("number of bars per group:", n), quote=FALSE) } - - mySpace <- hsBpSpace(myWidth=myWidth, position=myPosition, + + mySpace <- hsBpSpace(myWidth=myWidth, position=myPosition, myXlim=myXlim, myBeside=myBeside,barsPerGroup=n, innerSpace=myInnerSpace) - + # Calculate the limits if (is.null(myXlim)) { if (myBeside) { - myXlim <- hsBpDefaultXlim(myPosition, + myXlim <- hsBpDefaultXlim(myPosition, hsBpBargroupWidth(myWidth, n, myInnerSpace)) } else { myXlim <- hsBpDefaultXlim(myPosition, myWidth) } - } + } if (dbg) { print(paste("xlim before transition:", paste(myXlim,collapse=",")),quote=FALSE) } - + # R's barplot function only works as expected (my personal experience) # if the x range starts at 0. Therefore why we "shift" the myXlim range to # (0,Xmax-Xmin) here. - myXlim <- c(0, myXlim[2] - myXlim[1]) + myXlim <- c(0, myXlim[2] - myXlim[1]) } else { # If no positions are given, we do not give limits to barplot() myXlim = NULL } - + # R's barplot function is able to arrange the bars "decreasingly" by just - # switching the x limits... + # switching the x limits... if (myReverse) { myXlim = rev(myXlim) } - + if (dbg) { print("Running barplot with:", quote=FALSE) - print(paste("space =", paste(mySpace,collapse=","), + print(paste("space =", paste(mySpace,collapse=","), ", xlim =", paste(myXlim,collapse=",")), quote=FALSE) print("myHeight:") print(myHeight) } - - # Finally call R's barplot function... - barplot( - height = myHeight, - width = myWidth, + + # Finally call R's barplot function... + graphics::barplot( + height = myHeight, + width = myWidth, space = mySpace, - xlim = myXlim, + xlim = myXlim, ylim = myYlim, beside = myBeside, ...) - + # Add an axis on top if (myAxis) { if (!is.null(myXlim)) { ma <- abs(myXlim[2] - myXlim[1]) - axis(side=3, xaxp=c(0,ma,ma)) + graphics::axis(side = 3, xaxp=c(0, ma, ma)) } else { - axis(side=3) + graphics::axis(side = 3) } } - + if (myValLabs && myBeside) { hsPutValueLabels(myHeight, myPosition, myWidth, mySpace, myYlim[2]) } } # hsPutValueLabels ------------------------------------------------------------- -hsPutValueLabels <- function -### Put values on top of the bars -( - myHeight, - myPosition, - myWidth, - mySpace, - myYmax -) + +#' Put Values on Top of the Bars +#' +#' @param myHeight heights of bars +#' @param myPosition x-positions of bars +#' @param myWidth widths of bars +#' @param mySpace space between bars in a bar group +#' @param myYmax y limit. Used to determine the distance between top of bar and +#' labels on top +hsPutValueLabels <- function(myHeight, myPosition, myWidth, mySpace, myYmax) { - # Put the values on top of the bars i <- 1 for (myVal in (myHeight)) { - if (! is.null(myPosition)) { + if (! is.null(myPosition)) { myx <- myPosition[i] - min(myPosition) + myWidth/2 } else { @@ -363,70 +390,82 @@ hsPutValueLabels <- function myx <- ms + (i-1)*(myWidth + ms) + myWidth/2 } myy <- myVal + 0.06 * myYmax - text(myx, myy, myVal) + graphics::text(myx, myy, myVal) i <- i + 1 } } # hsBarplot2 ------------------------------------------------------------------- + +#' barplot() with X-Position Support (2) +#' +#' Extended version of R barplot function, enabling x positioning of the bars. +#' +#' @param myHeight Vector or matrix containing the bar heights, see R's barplot +#' function. +#' @param myPos Vector containing the x-positions of the bars/bar groups. +#' @param myWidth Bar widths. If bars are to be stacked (isp = NULL, see below) +#' w represents the widths of the stacked bars. If bars shall be plotted side +#' by side instead of stacked (isp >= 0) w represents the widths of the bars +#' within one and the same bar group. Corresponding bars of different groups +#' will always have the same width. +#' @param myBeside If TRUE, bars within a bar group are arranged side by side +#' instead of stacked. +#' @param myInnerSpace "Inner" space between bars of the same bar group (only +#' relevant if y is a matrix and not a vector). If NULL, bars of the same bar +#' group will be stacked +#' @param myValLabs whether to put value labels on top of the bars +#' @param dx x offset for text labels. Default: 0 +#' @param dy y offset for text labels. Default: 0 +#' @param dbg whether to print debug messages or not +#' @param \dots further arguments passed to \code{\link{barplot}} +#' @export hsBarplot2 <- function -### Extended version of R barplot function, enabling x positioning of the bars. ( - myHeight, - ### Vector or matrix containing the bar heights, see R's barplot function. - myPos = NULL, - ### Vector containing the x-positions of the bars/bar groups. - myWidth = 1, - ### Bar widths. If bars are to be stacked (isp = NULL, see below) w represents - ### the widths of the stacked bars. If bars shall be plotted side by side - ### instead of stacked (isp >= 0) w represents the widths of the bars within - ### one and the same bar group. Corresponding bars of different groups will - ### always have the same width. - myBeside = FALSE, - ### If TRUE, bars within a bar group are arranged side by side instead of - ### stacked. - myInnerSpace = 0, - ### "Inner" space between bars of the same bar group (only relevant if y is - ### a matrix and not a vector). If NULL, bars of the same bar group will be - ### stacked - myValLabs = TRUE, - dx = 0, - dy = 0, - dbg = FALSE, + myHeight, + myPos = NULL, + myWidth = 1, + myBeside = FALSE, + myInnerSpace = 0, + myValLabs = TRUE, + dx = 0, + dy = 0, + dbg = FALSE, ... -) +) { - if (dbg) { cat("-------------------------------\n") cat("In hsBarplot2():\n") cat(sprintf("*** myHeight: %s\n", paste(myHeight, collapse = ","))) - print(str(myHeight)) + print(utils::str(myHeight)) cat(sprintf("*** myPos: %s\n", paste(myPos, collapse = ","))) cat(sprintf("*** myWidth: %f\n", myWidth)) cat(sprintf("*** myBeside: %s\n", myBeside)) cat(sprintf("*** myInnerSpace: %f\n", myInnerSpace)) } - + # We expect that all bars have the same width! if (length(myWidth) != 1) { #@2011-12-19: stop instead of "print" and "return" stop("All bars must have the same width (length of myWidth must be one)!\n") } - + mySpace <- NULL N <- ncol(myHeight) n <- 1 + if (myBeside) { n <- nrow(myHeight) } - cat(paste("N =", N, " (columns), n =", n, " (rows)\n")) - + + cat(paste("N =", N, " (columns), n =", n, " (rows)\n")) + if (!is.null(myPos)) { cat("Positions: ") print(myPos) w <- n * myWidth + (n-1) * myInnerSpace - c1 <- c(myPos - w/2, NA) + c1 <- c(myPos - w/2, NA) c2 <- c(0, myPos + w/2) mySpace <- (c1 - c2)[1:length(myPos)] if (myBeside) { @@ -435,19 +474,19 @@ hsBarplot2 <- function mySpace[1 + n*(0:(N-1))] <- mySpaceTmp } mySpace <- mySpace / mean(myWidth) - } - - # Call barplot - barplot( - height = myHeight, - width = myWidth, - space = mySpace, + } + + # Call barplot + graphics::barplot( + height = myHeight, + width = myWidth, + space = mySpace, beside = myBeside, ...) - axis(1) - grid() + graphics::axis(1) + graphics::grid() - # If desired, put value labels above the bars + # If desired, put value labels above the bars if (myValLabs) { if (! myBeside) { myx <- rep(myPos, nrow(myHeight)) @@ -483,7 +522,8 @@ hsBarplot2 <- function cat(sprintf("myv: %s\n", paste(myv, collapse = ","))) } # adj = c(0, 0.5): horizontally left justified and vertically centered - text(x = myx+dx, y = myy+dy, labels = myv, adj = c(0,0.5), cex = 0.7) - + graphics::text( + x = myx + dx, y = myy + dy, labels = myv, adj = c(0, 0.5), cex = 0.7 + ) } } diff --git a/README.md b/README.md new file mode 100644 index 0000000..a21acc7 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +[![R-CMD-check](https://github.com/KWB-R/kwb.barplot/workflows/R-CMD-check/badge.svg)](https://github.com/KWB-R/kwb.barplot/actions?query=workflow%3AR-CMD-check) +[![pkgdown](https://github.com/KWB-R/kwb.barplot/workflows/pkgdown/badge.svg)](https://github.com/KWB-R/kwb.barplot/actions?query=workflow%3Apkgdown) +[![codecov](https://codecov.io/github/KWB-R/kwb.barplot/branch/main/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.barplot) +[![Project Status](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) +[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/kwb.barplot)]() + +# kwb.barplot + +Barplot function that can arrange bars along the x axis. + +## Installation + +For details on how to install KWB-R packages checkout our [installation tutorial](https://kwb-r.github.io/kwb.pkgbuild/articles/install.html). + +```r +### Optionally: specify GitHub Personal Access Token (GITHUB_PAT) +### See here why this might be important for you: +### https://kwb-r.github.io/kwb.pkgbuild/articles/install.html#set-your-github_pat + +# Sys.setenv(GITHUB_PAT = "mysecret_access_token") + +# Install package "remotes" from CRAN +if (! require("remotes")) { + install.packages("remotes", repos = "https://cloud.r-project.org") +} + +# Install KWB package 'kwb.barplot' from GitHub +remotes::install_github("KWB-R/kwb.barplot") +``` + +## Documentation + +Release: [https://kwb-r.github.io/kwb.barplot](https://kwb-r.github.io/kwb.barplot) + +Development: [https://kwb-r.github.io/kwb.barplot/dev](https://kwb-r.github.io/kwb.barplot/dev) diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..3e45986 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,15 @@ +authors: + Hauke Sonnenberg: + href: https://github.com/hsonne + Michael Rustler: + href: https://mrustl.de + Kompetenzzentrum Wasser Berlin gGmbH (KWB): + href: http://www.kompetenz-wasser.de + html: +template: + params: + bootswatch: cerulean +development: + mode: auto + diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true diff --git a/index.md b/index.md new file mode 100644 index 0000000..4ffcc9a --- /dev/null +++ b/index.md @@ -0,0 +1,27 @@ +[![R-CMD-check](https://github.com/KWB-R/kwb.barplot/workflows/R-CMD-check/badge.svg)](https://github.com/KWB-R/kwb.barplot/actions?query=workflow%3AR-CMD-check) +[![pkgdown](https://github.com/KWB-R/kwb.barplot/workflows/pkgdown/badge.svg)](https://github.com/KWB-R/kwb.barplot/actions?query=workflow%3Apkgdown) +[![codecov](https://codecov.io/github/KWB-R/kwb.barplot/branch/main/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.barplot) +[![Project Status](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) +[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/kwb.barplot)]() + +Barplot function that can arrange bars along the x axis. + +## Installation + +For details on how to install KWB-R packages checkout our [installation tutorial](https://kwb-r.github.io/kwb.pkgbuild/articles/install.html). + +```r +### Optionally: specify GitHub Personal Access Token (GITHUB_PAT) +### See here why this might be important for you: +### https://kwb-r.github.io/kwb.pkgbuild/articles/install.html#set-your-github_pat + +# Sys.setenv(GITHUB_PAT = "mysecret_access_token") + +# Install package "remotes" from CRAN +if (! require("remotes")) { + install.packages("remotes", repos = "https://cloud.r-project.org") +} + +# Install KWB package 'kwb.barplot' from GitHub +remotes::install_github("KWB-R/kwb.barplot") +``` diff --git a/kwb.barplot.Rproj b/kwb.barplot.Rproj index 8e3c2eb..69fafd4 100644 --- a/kwb.barplot.Rproj +++ b/kwb.barplot.Rproj @@ -1,7 +1,7 @@ Version: 1.0 -RestoreWorkspace: Default -SaveWorkspace: Default +RestoreWorkspace: No +SaveWorkspace: No AlwaysSaveHistory: Default EnableCodeIndexing: Yes @@ -11,3 +11,12 @@ Encoding: UTF-8 RnwWeave: Sweave LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/man/hsBarplot.Rd b/man/hsBarplot.Rd new file mode 100644 index 0000000..68a922f --- /dev/null +++ b/man/hsBarplot.Rd @@ -0,0 +1,62 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hsLibBarplot.R +\name{hsBarplot} +\alias{hsBarplot} +\title{barplot() with X-Position Support} +\usage{ +hsBarplot( + myHeight, + myWidth = 1, + myPosition = NULL, + myXlim = NULL, + myBeside = FALSE, + myReverse = FALSE, + myInnerSpace = 0, + myAxis = TRUE, + dbg = FALSE, + myYlim = NULL, + myValLabs = FALSE, + ... +) +} +\arguments{ +\item{myHeight}{Vector or matrix containing the bar heights, see R's barplot +function.} + +\item{myWidth}{Bar widths. If bars are to be stacked (isp = NULL, see below) +w represents the widths of the stacked bars. If bars shall be plotted side +by side instead of stacked (isp >= 0) w represents the widths of the bars +within one and the same bar group. Corresponding bars of different groups +will always have the same width.} + +\item{myPosition}{Vector containing the x-positions of the bars/bar groups.} + +\item{myXlim}{Vector containing minimum and maximum x-value to be shown in +the plot.} + +\item{myBeside}{If TRUE, bars within a bar group are arranged side by side +instead of stacked.} + +\item{myReverse}{If TRUE, the bars in the plot will reverted, i.e. they will +be arranged according to decreasing x-values.} + +\item{myInnerSpace}{"Inner" space between bars of the same bar group (only +relevant if y is a matrix and not a vector). If NULL, bars of the same bar +group will be stacked} + +\item{myAxis}{whether to draw an axis or not} + +\item{dbg}{whether to print debug messages or not} + +\item{myYlim}{ylim vector} + +\item{myValLabs}{whether to put value labels on top of the bars} + +\item{\dots}{further arguments passed to \code{\link{barplot}}} +} +\description{ +Extended version of R barplot function, enabling x positioning of the bars. +} +\examples{ +hsBarplot(1:10, myWidth = 0.2, myPosition = 0.1 * c(1:10)^2) +} diff --git a/man/hsBarplot2.Rd b/man/hsBarplot2.Rd new file mode 100644 index 0000000..024fb4c --- /dev/null +++ b/man/hsBarplot2.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hsLibBarplot.R +\name{hsBarplot2} +\alias{hsBarplot2} +\title{barplot() with X-Position Support (2)} +\usage{ +hsBarplot2( + myHeight, + myPos = NULL, + myWidth = 1, + myBeside = FALSE, + myInnerSpace = 0, + myValLabs = TRUE, + dx = 0, + dy = 0, + dbg = FALSE, + ... +) +} +\arguments{ +\item{myHeight}{Vector or matrix containing the bar heights, see R's barplot +function.} + +\item{myPos}{Vector containing the x-positions of the bars/bar groups.} + +\item{myWidth}{Bar widths. If bars are to be stacked (isp = NULL, see below) +w represents the widths of the stacked bars. If bars shall be plotted side +by side instead of stacked (isp >= 0) w represents the widths of the bars +within one and the same bar group. Corresponding bars of different groups +will always have the same width.} + +\item{myBeside}{If TRUE, bars within a bar group are arranged side by side +instead of stacked.} + +\item{myInnerSpace}{"Inner" space between bars of the same bar group (only +relevant if y is a matrix and not a vector). If NULL, bars of the same bar +group will be stacked} + +\item{myValLabs}{whether to put value labels on top of the bars} + +\item{dx}{x offset for text labels. Default: 0} + +\item{dy}{y offset for text labels. Default: 0} + +\item{dbg}{whether to print debug messages or not} + +\item{\dots}{further arguments passed to \code{\link{barplot}}} +} +\description{ +Extended version of R barplot function, enabling x positioning of the bars. +} diff --git a/man/hsBpBargroupWidth.Rd b/man/hsBpBargroupWidth.Rd new file mode 100644 index 0000000..023947f --- /dev/null +++ b/man/hsBpBargroupWidth.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hsLibBarplot.R +\name{hsBpBargroupWidth} +\alias{hsBpBargroupWidth} +\title{Width of Bargroup} +\usage{ +hsBpBargroupWidth(myWidth, myBarsPerGroup, myInnerSpace) +} +\arguments{ +\item{myWidth}{widths of the bars in one group} + +\item{myBarsPerGroup}{number of bars per group} + +\item{myInnerSpace}{inner space between bars in a bar group} +} +\value{ +vector of numeric of length one +} +\description{ +The widths represent the widths of the bars in one group. It is calculated +as: sum(myWidth) + (myBarsPerGroup - 1) * myInnerSpace +} diff --git a/man/hsBpDefaultXlim.Rd b/man/hsBpDefaultXlim.Rd new file mode 100644 index 0000000..24335b8 --- /dev/null +++ b/man/hsBpDefaultXlim.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hsLibBarplot.R +\name{hsBpDefaultXlim} +\alias{hsBpDefaultXlim} +\title{Default xlim for Barplot} +\usage{ +hsBpDefaultXlim(position, barGroupWidth = 1) +} +\arguments{ +\item{position}{vector of x-positions of bars} + +\item{barGroupWidth}{bargroup widths. Default: 1} +} +\value{ +vector of numeric of length two +} +\description{ +Default xlim for Barplot +} diff --git a/man/hsBpGetXlim.Rd b/man/hsBpGetXlim.Rd new file mode 100644 index 0000000..35b6111 --- /dev/null +++ b/man/hsBpGetXlim.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hsLibBarplot.R +\name{hsBpGetXlim} +\alias{hsBpGetXlim} +\title{xlim for Barplot} +\usage{ +hsBpGetXlim(myData, myWidth = 1, mySpace = NULL, myBeside = FALSE) +} +\arguments{ +\item{myData}{corresponding to "height" in \code{\link{barplot}}} + +\item{myWidth}{corresponding to "width" in \code{\link{barplot}}} + +\item{mySpace}{corresponding to "space" in \code{\link{barplot}}} + +\item{myBeside}{corresponding to "beside" in \code{\link{barplot}}} +} +\value{ +vector of numeric of length two +} +\description{ +Depending on the argument values that are passed to \code{barplot()} a good +vector to be used as xlim is returned. +} diff --git a/man/hsBpNumBars.Rd b/man/hsBpNumBars.Rd new file mode 100644 index 0000000..078c78d --- /dev/null +++ b/man/hsBpNumBars.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hsLibBarplot.R +\name{hsBpNumBars} +\alias{hsBpNumBars} +\title{Number of Bar Groups and Bars Per Group Produced by barplot()} +\usage{ +hsBpNumBars(myData, myBeside) +} +\arguments{ +\item{myData}{as passed in \code{height} to \code{\link{barplot}}} + +\item{myBeside}{as passed in \code{beside} to \code{\link{barplot}}} +} +\value{ +Returns tupel containing N = number of bar groups and n = number of +bars per group +} +\description{ +Number of bar groups (N) and bars per group (n) produced by barplot(), +depending on given data and parameter "beside" +} diff --git a/man/hsBpSpace.Rd b/man/hsBpSpace.Rd new file mode 100644 index 0000000..a93f539 --- /dev/null +++ b/man/hsBpSpace.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hsLibBarplot.R +\name{hsBpSpace} +\alias{hsBpSpace} +\title{Spaces Between Bars} +\usage{ +hsBpSpace( + myWidth, + position, + myXlim = NULL, + myBeside = FALSE, + barsPerGroup = 1, + innerSpace = 0, + dbg = FALSE +) +} +\arguments{ +\item{myWidth}{Bar widths. If bars are to be stacked (isp = NULL, see below) +w represents the widths of the different (stacked) bars. If bars are to be +arranged side by side (isp >= 0) w represents the widths of the bars within +one and the same bar group. Corresponding bars of different groups will +always have the same width.} + +\item{position}{X-positions of bars/bar groups} + +\item{myXlim}{Vector containing minimum and maximum x-value to be shown in +the plot.} + +\item{myBeside}{If TRUE, bars of a bar group are not stacked but arranged +side by side. Then, \code{myWidth} contains the widths of the bars within +one group. Otherwise (\code{myBeside} = FALSE) \code{myWidth} contains the +widths of the (stacked) bars.} + +\item{barsPerGroup}{Number of bars per group. If this parameter is greater +than 1, it means that bars are to be arranged side by side instead of +stacked.} + +\item{innerSpace}{"Inner" space between bars of the same group (only used if +bpg > 1).} + +\item{dbg}{whether to print debug messages or not} +} +\value{ +Returns a space vector as needed to be passed to the barplot function +} +\description{ +Calculates the spaces between bars of widths w at positions x as difference +between the x values minus half the width of the bars/bar groups. +} diff --git a/man/hsPutValueLabels.Rd b/man/hsPutValueLabels.Rd new file mode 100644 index 0000000..b630417 --- /dev/null +++ b/man/hsPutValueLabels.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hsLibBarplot.R +\name{hsPutValueLabels} +\alias{hsPutValueLabels} +\title{Put Values on Top of the Bars} +\usage{ +hsPutValueLabels(myHeight, myPosition, myWidth, mySpace, myYmax) +} +\arguments{ +\item{myHeight}{heights of bars} + +\item{myPosition}{x-positions of bars} + +\item{myWidth}{widths of bars} + +\item{mySpace}{space between bars in a bar group} + +\item{myYmax}{y limit. Used to determine the distance between top of bar and +labels on top} +} +\description{ +Put Values on Top of the Bars +}