diff --git a/.Rbuildignore b/.Rbuildignore index 89002b5..be1999f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,6 @@ usethis_hist.R ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^cran-comments\.md$ +.DS_Store +^CRAN-SUBMISSION$ diff --git a/.gitignore b/.gitignore index 138866d..c5edce2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .Ruserdata inst/doc docs +.DS_Store diff --git a/DESCRIPTION b/DESCRIPTION index 34d3f42..68f0b87 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,13 @@ Type: Package Package: densityarea -Title: Areas of Bivarate Density Distributions +Title: Polygons of Bivariate Density Distributions Version: 0.1.0.9000 Authors@R: - person("Josef", "Fruehwald", , "jofrhwld@gmail.com", role = c("aut", "cre")) -Description: With bivarate data, it is possible to calculate 2-dimensional - kernel density estimates that return polygons at given levels of - probablity. `densityarea` returns these polygons for analysis, - including for calculating their area. + person("Josef", "Fruehwald", , "jofrhwld@gmail.com", role = c("aut", "cre", "cph")) +Description: With bivariate data, it is possible to calculate + 2-dimensional kernel density estimates that return polygons at given + levels of probability. 'densityarea' returns these polygons for + analysis, including for calculating their area. License: GPL (>= 3) URL: https://github.com/JoFrhwld/densityarea, https://jofrhwld.github.io/densityarea/ diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..a863288 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,3 @@ +# densityarea 0.1.0 + +* Initial CRAN submission. diff --git a/R/data.R b/R/data.R index 4518f07..6238951 100644 --- a/R/data.R +++ b/R/data.R @@ -25,13 +25,13 @@ #' Amogh Gulati, Coles, A., Veaux, C., Eren, E., Mishra, H., Paweł Potrykus, #' Jung, S., Sereda, T., Mestrou, T., Michaelasocolof, & Vannawillerton. (2022). #' MontrealCorpusTools/Montreal-Forced-Aligner: Version 2.0.1 (v2.0.1) -#' [https://doi.org/10.5281/ZENODO.6658586](https://doi.org/10.5281/ZENODO.6658586) +#' \doi{10.5281/ZENODO.6658586} #' #' @source Pitt, M. A., Dilley, L., Johnson, K., Kiesling, S., Raymond, W., #' Hume, E., & Fosler-Lussier, E. (2007). Buckeye Corpus of Conversational #' Speech (2nd release). Department of Psychology, Ohio State University. -#' [www.buckeyecorpus.osu.edu](www.buckeyecorpus.osu.edu) +#' [https://buckeyecorpus.osu.edu/](https://buckeyecorpus.osu.edu/) #' #' @source Rosenfelder, I., Fruehwald, J., Brickhouse, C., Evanini, K., #' Seyfarth, S., Gorman, K., Prichard, H., & Yuan, J. (2022). diff --git a/R/density_area.R b/R/density_area.R index 5b65e72..26d6f6d 100644 --- a/R/density_area.R +++ b/R/density_area.R @@ -289,6 +289,27 @@ density_polygons <- function(x, #' If only one or the other of `rangex` and `rangey` are defined, `range_mult` #' will be used to produce the range of the undefined one. #' +#' @returns A list of data frames, if `as_list=TRUE`, or just a data frame, +#' if `as_list=FALSE`. +#' +#' ## Data frame output +#' +#' If `as_sf=FALSE`, the data frame has the following columns: +#' \describe{ +#' \item{level_id}{An integer id for each probability level} +#' \item{prob}{The probability level (originally passed to `probs`)} +#' \item{area}{The area of the HDR polygon} +#' } +#' +#' ## sf output +#' If `as_sf=TRUE`, the data frame has the following columns: +#' \describe{ +#' \item{level_id}{An integer id for each probability level} +#' \item{prob}{The probability level (originally passed to `probs`)} +#' \item{geometry}{The `sf::st_polygon()` of the HDR} +#' \item{area}{The area of the HDR polygon} +#' } +#' #' @example inst/examples/density_area_example.R #' #' @importFrom dplyr .data diff --git a/README.Rmd b/README.Rmd index 2c47fd5..092ec4d 100644 --- a/README.Rmd +++ b/README.Rmd @@ -21,11 +21,12 @@ knitr::opts_chunk$set( [![R-CMD-check](https://github.com/JoFrhwld/densityarea/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/JoFrhwld/densityarea/actions/workflows/R-CMD-check.yaml) +[![CRAN status](https://www.r-pkg.org/badges/version/densityarea)](https://CRAN.R-project.org/package=densityarea) The package `{ggdensity}`[^1] allows for plotting interpretable bivariate densities by using highest density ranges (HDRs). For example: -[^1]: Otto J, Kahle D (2023). *ggdensity: Interpretable Bivariate Density Visualization with 'ggplot2'*. +[^1]: Otto J, Kahle D (2023). *ggdensity: Interpretable Bivariate Density Visualization with 'ggplot2'*. ```{r} #| fig-width: 4 @@ -50,7 +51,12 @@ ggplot(df, aes(x,y))+ ## Installation -You can install the development version of `{densityarea}` from [GitHub](https://github.com/) with: +You can install `{densityarea}` from CRAN with: +```r +install.packages("densityarea") +``` + +Or you can install the development version from [GitHub](https://github.com/) with: ``` r # install.packages("devtools") diff --git a/README.md b/README.md index 057f0e0..0c3ca2d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ [![R-CMD-check](https://github.com/JoFrhwld/densityarea/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/JoFrhwld/densityarea/actions/workflows/R-CMD-check.yaml) +[![CRAN +status](https://www.r-pkg.org/badges/version/densityarea)](https://CRAN.R-project.org/package=densityarea) The package `{ggdensity}`[^1] allows for plotting interpretable @@ -34,7 +36,13 @@ analysis. ## Installation -You can install the development version of `{densityarea}` from +You can install `{densityarea}` from CRAN with: + +``` r +install.packages("densityarea") +``` + +Or you can install the development version from [GitHub](https://github.com/) with: ``` r @@ -98,5 +106,5 @@ information on using spatial polygons, see `vignette("sf-operations")`. [^1]: Otto J, Kahle D (2023). *ggdensity: Interpretable Bivariate Density Visualization with ‘ggplot2’*. - - + + diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 0000000..f06b9ba --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,41 @@ +## Resubmission + +This is a resubmission. In this version I have: + +* written the package name in single quotes in the description. +* There are no references in the description field to format. + +## R CMD check results + +0 errors | 0 warnings | 1 note + +* This is a new release. + +## Included data license information + +* `s01.txt` is "supplemental annotation" of Buckeye Corpus content, which +licensees are permitted to distribute. + +The relevant section of the Buckeye Corpus License reads: + +> Licensee may augment the Content with supplemental +annotations. Such annotations shall not constitute a +derivative work or Improvement of the Content. +Furthermore, these supplemental annotations may be +distributed by the Licensee as long as the other +provisions of this Agreement are satisfied, including but +not limited to the prohibition on the creation of +derivative works or the distribution of the Content by the +Licensee. + +## Description refrerences + +There are no references in my package description. + +## Spellcheck + +Words flagged as possibly misspelled are not misspelled: + +* bivariate +* densityarea + diff --git a/inst/examples/density_area_example.R b/inst/examples/density_area_example.R index 0dadc54..cb31a9c 100644 --- a/inst/examples/density_area_example.R +++ b/inst/examples/density_area_example.R @@ -1,9 +1,9 @@ library(densityarea) -library(ggplot2) library(dplyr) -library(tidyr) library(sf) +ggplot2_inst <- require(ggplot2) + # basic usage set.seed(10) @@ -18,9 +18,11 @@ density_area(x, head(poly_areas_df) # Plotting the relationship between probability level and area -ggplot(poly_areas_df, - aes(prob, area)) + - geom_line() +if(ggplot2_inst){ + ggplot(poly_areas_df, + aes(prob, area)) + + geom_line() +} # Tidyverse usage @@ -42,9 +44,11 @@ s01 |> probs = ppoints(10))) -> s01_areas_df -s01_areas_df |> - ggplot(aes(prob, area)) + - geom_line() +if(ggplot2_inst){ + s01_areas_df |> + ggplot(aes(prob, area)) + + geom_line() +} ### Including sf output @@ -57,7 +61,9 @@ s01 |> st_sf() -> s01_areas_sf -s01_areas_sf |> - arrange(desc(prob)) |> - ggplot() + - geom_sf(aes(fill = area)) +if(ggplot2_inst){ + s01_areas_sf |> + arrange(desc(prob)) |> + ggplot() + + geom_sf(aes(fill = area)) +} diff --git a/inst/examples/density_polygon_example.R b/inst/examples/density_polygon_example.R index 5e6ad02..a5d0545 100644 --- a/inst/examples/density_polygon_example.R +++ b/inst/examples/density_polygon_example.R @@ -1,10 +1,11 @@ library(densityarea) -library(ggplot2) library(dplyr) library(purrr) -library(tidyr) library(sf) +ggplot2_inst <- require(ggplot2) +tidyr_inst <- require(tidyr) + set.seed(10) x <- c(rnorm(100)) y <- c(rnorm(100)) @@ -18,10 +19,11 @@ head(poly_df) # It's necessary to specify a grouping factor that combines `level_id` and `id` # for cases of multimodal density distributions -ggplot(poly_df, aes(x, y)) + - geom_path(aes(group = paste0(level_id, id), - color = prob)) - +if(ggplot2_inst){ + ggplot(poly_df, aes(x, y)) + + geom_path(aes(group = paste0(level_id, id), + color = prob)) +} # sf output poly_sf <- density_polygons(x, @@ -32,11 +34,12 @@ poly_sf <- density_polygons(x, head(poly_sf) # `geom_sf()` is from the `{sf}` package. -poly_sf |> - arrange(desc(prob)) |> - ggplot() + - geom_sf(aes(fill = prob)) - +if(ggplot2_inst){ + poly_sf |> + arrange(desc(prob)) |> + ggplot() + + geom_sf(aes(fill = prob)) +} # Tidyverse usage @@ -56,11 +59,13 @@ s01 |> probs = ppoints(5))) -> speaker_poly_df -speaker_poly_df |> - ggplot(aes(log_F2, log_F1)) + - geom_path(aes(group = paste0(level_id, id), - color = prob)) + - coord_fixed() +if(ggplot2_inst){ + speaker_poly_df |> + ggplot(aes(log_F2, log_F1)) + + geom_path(aes(group = paste0(level_id, id), + color = prob)) + + coord_fixed() +} ### sf output s01 |> @@ -72,34 +77,39 @@ s01 |> st_sf() -> speaker_poly_sf -speaker_poly_sf |> - ggplot() + - geom_sf(aes(color = prob), - fill = NA) +if(ggplot2_inst){ + speaker_poly_sf |> + ggplot() + + geom_sf(aes(color = prob), + fill = NA) +} ## basic usage with dplyr::summarise() ### data frame output -s01 |> - group_by(name) |> - summarise(poly = density_polygons(log_F2, - log_F1, - probs = ppoints(5), - as_list = TRUE)) |> - unnest(poly) -> - speaker_poly_df - +if(tidyr_inst){ + s01 |> + group_by(name) |> + summarise(poly = density_polygons(log_F2, + log_F1, + probs = ppoints(5), + as_list = TRUE)) |> + unnest(poly) -> + speaker_poly_df +} ### sf output -s01 |> - group_by(name) |> - summarise(poly = density_polygons( - log_F2, - log_F1, - probs = ppoints(5), - as_list = TRUE, - as_sf = TRUE - )) |> - unnest(poly) |> - st_sf() -> - speaker_poly_sf +if(tidyr_inst){ + s01 |> + group_by(name) |> + summarise(poly = density_polygons( + log_F2, + log_F1, + probs = ppoints(5), + as_list = TRUE, + as_sf = TRUE + )) |> + unnest(poly) |> + st_sf() -> + speaker_poly_sf +} diff --git a/man/density_area.Rd b/man/density_area.Rd index 2331a2a..00e82d5 100644 --- a/man/density_area.Rd +++ b/man/density_area.Rd @@ -34,6 +34,30 @@ probability density will be estimated.} \item{...}{Additional arguments to be passed to \code{\link[ggdensity:get_hdr]{ggdensity::get_hdr()}}} } +\value{ +A list of data frames, if \code{as_list=TRUE}, or just a data frame, +if \code{as_list=FALSE}. +\subsection{Data frame output}{ + +If \code{as_sf=FALSE}, the data frame has the following columns: +\describe{ +\item{level_id}{An integer id for each probability level} +\item{prob}{The probability level (originally passed to \code{probs})} +\item{area}{The area of the HDR polygon} +} +} + +\subsection{sf output}{ + +If \code{as_sf=TRUE}, the data frame has the following columns: +\describe{ +\item{level_id}{An integer id for each probability level} +\item{prob}{The probability level (originally passed to \code{probs})} +\item{geometry}{The \code{sf::st_polygon()} of the HDR} +\item{area}{The area of the HDR polygon} +} +} +} \description{ A convenience function to get just the areas of density polygons. } @@ -44,11 +68,11 @@ will be used to produce the range of the undefined one. } \examples{ library(densityarea) -library(ggplot2) library(dplyr) -library(tidyr) library(sf) +ggplot2_inst <- require(ggplot2) + # basic usage set.seed(10) @@ -63,9 +87,11 @@ density_area(x, head(poly_areas_df) # Plotting the relationship between probability level and area -ggplot(poly_areas_df, - aes(prob, area)) + - geom_line() +if(ggplot2_inst){ + ggplot(poly_areas_df, + aes(prob, area)) + + geom_line() +} # Tidyverse usage @@ -87,9 +113,11 @@ s01 |> probs = ppoints(10))) -> s01_areas_df -s01_areas_df |> - ggplot(aes(prob, area)) + - geom_line() +if(ggplot2_inst){ + s01_areas_df |> + ggplot(aes(prob, area)) + + geom_line() +} ### Including sf output @@ -102,8 +130,10 @@ s01 |> st_sf() -> s01_areas_sf -s01_areas_sf |> - arrange(desc(prob)) |> - ggplot() + - geom_sf(aes(fill = area)) +if(ggplot2_inst){ + s01_areas_sf |> + arrange(desc(prob)) |> + ggplot() + + geom_sf(aes(fill = area)) +} } diff --git a/man/density_polygons.Rd b/man/density_polygons.Rd index 27b9fe3..a0bafb2 100644 --- a/man/density_polygons.Rd +++ b/man/density_polygons.Rd @@ -80,12 +80,13 @@ will be used to produce the range of the undefined one. } \examples{ library(densityarea) -library(ggplot2) library(dplyr) library(purrr) -library(tidyr) library(sf) +ggplot2_inst <- require(ggplot2) +tidyr_inst <- require(tidyr) + set.seed(10) x <- c(rnorm(100)) y <- c(rnorm(100)) @@ -99,10 +100,11 @@ head(poly_df) # It's necessary to specify a grouping factor that combines `level_id` and `id` # for cases of multimodal density distributions -ggplot(poly_df, aes(x, y)) + - geom_path(aes(group = paste0(level_id, id), - color = prob)) - +if(ggplot2_inst){ + ggplot(poly_df, aes(x, y)) + + geom_path(aes(group = paste0(level_id, id), + color = prob)) +} # sf output poly_sf <- density_polygons(x, @@ -113,11 +115,12 @@ poly_sf <- density_polygons(x, head(poly_sf) # `geom_sf()` is from the `{sf}` package. -poly_sf |> - arrange(desc(prob)) |> - ggplot() + - geom_sf(aes(fill = prob)) - +if(ggplot2_inst){ + poly_sf |> + arrange(desc(prob)) |> + ggplot() + + geom_sf(aes(fill = prob)) +} # Tidyverse usage @@ -137,11 +140,13 @@ s01 |> probs = ppoints(5))) -> speaker_poly_df -speaker_poly_df |> - ggplot(aes(log_F2, log_F1)) + - geom_path(aes(group = paste0(level_id, id), - color = prob)) + - coord_fixed() +if(ggplot2_inst){ + speaker_poly_df |> + ggplot(aes(log_F2, log_F1)) + + geom_path(aes(group = paste0(level_id, id), + color = prob)) + + coord_fixed() +} ### sf output s01 |> @@ -153,35 +158,40 @@ s01 |> st_sf() -> speaker_poly_sf -speaker_poly_sf |> - ggplot() + - geom_sf(aes(color = prob), - fill = NA) +if(ggplot2_inst){ + speaker_poly_sf |> + ggplot() + + geom_sf(aes(color = prob), + fill = NA) +} ## basic usage with dplyr::summarise() ### data frame output -s01 |> - group_by(name) |> - summarise(poly = density_polygons(log_F2, - log_F1, - probs = ppoints(5), - as_list = TRUE)) |> - unnest(poly) -> - speaker_poly_df - +if(tidyr_inst){ + s01 |> + group_by(name) |> + summarise(poly = density_polygons(log_F2, + log_F1, + probs = ppoints(5), + as_list = TRUE)) |> + unnest(poly) -> + speaker_poly_df +} ### sf output -s01 |> - group_by(name) |> - summarise(poly = density_polygons( - log_F2, - log_F1, - probs = ppoints(5), - as_list = TRUE, - as_sf = TRUE - )) |> - unnest(poly) |> - st_sf() -> - speaker_poly_sf +if(tidyr_inst){ + s01 |> + group_by(name) |> + summarise(poly = density_polygons( + log_F2, + log_F1, + probs = ppoints(5), + as_list = TRUE, + as_sf = TRUE + )) |> + unnest(poly) |> + st_sf() -> + speaker_poly_sf +} } diff --git a/man/s01.Rd b/man/s01.Rd index 967ccde..28fa054 100644 --- a/man/s01.Rd +++ b/man/s01.Rd @@ -27,12 +27,12 @@ McAuliffe, M., Fatchurrahman, M. R., GalaxieT, NTT123, Amogh Gulati, Coles, A., Veaux, C., Eren, E., Mishra, H., Paweł Potrykus, Jung, S., Sereda, T., Mestrou, T., Michaelasocolof, & Vannawillerton. (2022). MontrealCorpusTools/Montreal-Forced-Aligner: Version 2.0.1 (v2.0.1) -\url{https://doi.org/10.5281/ZENODO.6658586} +\doi{10.5281/ZENODO.6658586} Pitt, M. A., Dilley, L., Johnson, K., Kiesling, S., Raymond, W., Hume, E., & Fosler-Lussier, E. (2007). Buckeye Corpus of Conversational Speech (2nd release). Department of Psychology, Ohio State University. -\url{www.buckeyecorpus.osu.edu} +\url{https://buckeyecorpus.osu.edu/} Rosenfelder, I., Fruehwald, J., Brickhouse, C., Evanini, K., Seyfarth, S., Gorman, K., Prichard, H., & Yuan, J. (2022). diff --git a/renv.lock b/renv.lock index ae0e16d..fb8d6ba 100644 --- a/renv.lock +++ b/renv.lock @@ -171,10 +171,10 @@ }, "classInt": { "Package": "classInt", - "Version": "0.4-9", + "Version": "0.4-10", "Source": "Repository", "Repository": "CRAN", - "Hash": "bee651a42a89633eccb36dca9d9ab413", + "Hash": "f5a40793b1ae463a7ffb3902a95bf864", "Requirements": [ "KernSmooth", "class", @@ -281,6 +281,25 @@ "Hash": "b18a9cf3c003977b0cc49d5e76ebe48d", "Requirements": [] }, + "downlit": { + "Package": "downlit", + "Version": "0.4.3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "14fa1f248b60ed67e1f5418391a17b14", + "Requirements": [ + "brio", + "desc", + "digest", + "evaluate", + "fansi", + "memoise", + "rlang", + "vctrs", + "withr", + "yaml" + ] + }, "dplyr": { "Package": "dplyr", "Version": "1.1.3", @@ -548,6 +567,20 @@ "rlang" ] }, + "httr": { + "Package": "httr", + "Version": "1.4.7", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "ac107251d9d9fd72f0ca8049988f1d7f", + "Requirements": [ + "R6", + "curl", + "jsonlite", + "mime", + "openssl" + ] + }, "httr2": { "Package": "httr2", "Version": "0.2.3", @@ -725,6 +758,23 @@ "vctrs" ] }, + "pkgbuild": { + "Package": "pkgbuild", + "Version": "1.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "beb25b32a957a22a5c301a9e441190b3", + "Requirements": [ + "R6", + "callr", + "cli", + "crayon", + "desc", + "prettyunits", + "processx", + "rprojroot" + ] + }, "pkgconfig": { "Package": "pkgconfig", "Version": "2.0.3", @@ -733,18 +783,48 @@ "Hash": "01f28d4278f15c76cddbea05899c5d6f", "Requirements": [] }, + "pkgdown": { + "Package": "pkgdown", + "Version": "2.0.7", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "16fa15449c930bf3a7761d3c68f8abf9", + "Requirements": [ + "bslib", + "callr", + "cli", + "desc", + "digest", + "downlit", + "fs", + "httr", + "jsonlite", + "magrittr", + "memoise", + "purrr", + "ragg", + "rlang", + "rmarkdown", + "tibble", + "whisker", + "withr", + "xml2", + "yaml" + ] + }, "pkgload": { "Package": "pkgload", - "Version": "1.3.2.1", + "Version": "1.3.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "a7f498a1b2a4a6816148e498509f6e1d", + "Hash": "903d68319ae9923fb2e2ee7fa8230b91", "Requirements": [ "cli", "crayon", "desc", "fs", "glue", + "pkgbuild", "rlang", "rprojroot", "withr" @@ -760,10 +840,10 @@ }, "prettyunits": { "Package": "prettyunits", - "Version": "1.1.1", + "Version": "1.2.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "95ef9167b75dde9d2ccc3c7528393e7e", + "Hash": "6b01fc98b1e86c4f705ce9dcfd2f57c7", "Requirements": [] }, "processx": { @@ -820,6 +900,17 @@ "vctrs" ] }, + "ragg": { + "Package": "ragg", + "Version": "1.2.5", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "690bc058ea2b1b8a407d3cfe3dce3ef9", + "Requirements": [ + "systemfonts", + "textshaping" + ] + }, "rappdirs": { "Package": "rappdirs", "Version": "0.3.3", @@ -876,10 +967,10 @@ }, "rmarkdown": { "Package": "rmarkdown", - "Version": "2.24", + "Version": "2.25", "Source": "Repository", "Repository": "CRAN", - "Hash": "3854c37590717c08c32ec8542a2e0a35", + "Hash": "d65e35823c817f09f4de424fcdfa812a", "Requirements": [ "bslib", "evaluate", @@ -1033,6 +1124,16 @@ "Hash": "3a1be13d68d47a8cd0bfd74739ca1555", "Requirements": [] }, + "systemfonts": { + "Package": "systemfonts", + "Version": "1.0.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "90b28393209827327de889f49935140a", + "Requirements": [ + "cpp11" + ] + }, "testthat": { "Package": "testthat", "Version": "3.1.10", @@ -1060,6 +1161,17 @@ "withr" ] }, + "textshaping": { + "Package": "textshaping", + "Version": "0.3.6", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "1ab6223d3670fac7143202cb6a2d43d5", + "Requirements": [ + "cpp11", + "systemfonts" + ] + }, "tibble": { "Package": "tibble", "Version": "3.2.1", @@ -1134,10 +1246,10 @@ }, "units": { "Package": "units", - "Version": "0.8-3", + "Version": "0.8-4", "Source": "Repository", "Repository": "CRAN", - "Hash": "880ebc99e4d8f7e5f3caeb2f12632583", + "Hash": "e0fbcea25008a7540c83c2c294135de0", "Requirements": [ "Rcpp" ] @@ -1248,10 +1360,10 @@ }, "withr": { "Package": "withr", - "Version": "2.5.0", + "Version": "2.5.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "c0e49a9760983e81e55cdd9be92e7182", + "Hash": "d77c6f74be05c33164e33fbc85540cae", "Requirements": [] }, "wk": { diff --git a/usethis_hist.R b/usethis_hist.R index cfa3192..7d5d354 100644 --- a/usethis_hist.R +++ b/usethis_hist.R @@ -7,21 +7,21 @@ usethis::use_author( given = "Josef", family = "Fruehwald", email = "jofrhwld@gmail.com", - role = c("aut","cre") + role = c("aut","cre", "cph") ) usethis::use_roxygen_md() desc::desc_set( "Title", - "Areas of Bivarate Density Distributions" + "Polygons of Bivariate Density Distributions" ) desc::desc_set( "Description", - "With bivarate data, it is possible to calculate 2-dimensional kernel density - estimates that return polygons at given levels of probablity. `densityarea` + "With bivariate data, it is possible to calculate 2-dimensional kernel density + estimates that return polygons at given levels of probability. 'densityarea' returns these polygons for analysis, including for calculating their area.", normalize = T ) @@ -92,11 +92,16 @@ usethis::use_pkgdown() usethis::use_pkgdown_github_pages() -# Docs +# Docs ---- usethis::use_logo("logo.svg") +# CRAN submission prep ---- +usethis::use_news_md() +usethis::use_cran_comments() + + # CRAN publication usethis::use_cran_badge() usethis::use_github_release() diff --git a/vignettes/densityarea.Rmd b/vignettes/densityarea.Rmd index f69a5e7..99ebfe8 100644 --- a/vignettes/densityarea.Rmd +++ b/vignettes/densityarea.Rmd @@ -23,20 +23,28 @@ knitr::opts_chunk$set( To get started with using `{densityarea}`, we'll need to load some packages, and some data to work with. `{densityarea}` is meant to play nicely with tidyverse-style data processing, in addition to loading the -package itself, we'll aslo load `{dplyr}` and `{tidyr}`. We have the -option of working with the density polygons in the form of simple -features from `{sf}`, so we'll load that as well. Finally, we'll load -`{ggplot2}` and `{ggdensity}` for the sake of data visualization. +package itself, we'll also load `{dplyr}`. We have the option of working +with the density polygons in the form of simple features from `{sf}`, so +we'll load that as well. Finally, we'll load `{ggplot2}` and +`{ggdensity}` for the sake of data visualization. ```{r setup} +# package depends library(densityarea) library(dplyr) -library(tidyr) library(sf) -library(ggplot2) library(ggdensity) ``` +```{r setup2, eval = F} +#| package suggests +library(ggplot2) +``` + +```{r include=F} +ggplot2_inst <- require(ggplot2) +``` + The dataset `s01` is a data frame of vowel formant measurements. ```{r dataload} @@ -49,7 +57,7 @@ head(s01) Let's plot the original, raw data from `s01`, with the Highest Density Regions overlaid (thanks to the `{ggdensity}` package). -```{r fig.width=5, fig.height=3, fig.align='center', out.width="100%"} +```{r eval=ggplot2_inst, fig.width=5, fig.height=3, fig.align='center', out.width="100%"} ggplot(data = s01, aes(x = F2, y = F1) @@ -139,7 +147,7 @@ head(sixty_poly_df) Now, it's *possible* for the HDR polygon to actually come in multiple pieces, but in this case, there's just one polygon, so we can plot it. -```{r fig.width=4, fig.height=4, fig.align='center', out.width="80%"} +```{r eval=ggplot2_inst, fig.width=4, fig.height=4, fig.align='center', out.width="80%"} ggplot(sixty_poly_df, aes(lF2, lF1))+ geom_polygon( @@ -169,7 +177,7 @@ s01 |> head(multi_poly_df) ``` -```{r fig.width=4, fig.height=4, fig.align='center', out.width="80%"} +```{r eval=ggplot2_inst, fig.width=4, fig.height=4, fig.align='center', out.width="80%"} ggplot(multi_poly_df, aes(lF2, lF1))+ geom_polygon( @@ -210,7 +218,7 @@ multi_poly_sf And here's a plot. -```{r fig.width=4, fig.height=4, fig.align='center', out.width="80%"} +```{r eval=ggplot2_inst, fig.width=4, fig.height=4, fig.align='center', out.width="80%"} ggplot(multi_poly_sf)+ geom_sf(aes(color = prob), fill = NA) diff --git a/vignettes/sf-operations.Rmd b/vignettes/sf-operations.Rmd index f92bbed..af2122f 100644 --- a/vignettes/sf-operations.Rmd +++ b/vignettes/sf-operations.Rmd @@ -20,17 +20,29 @@ knitr::opts_chunk$set( Because `{densityarea}` can return `{sf}` polygons, this can allow you to use its functionality (see [this cheat sheet](https://github.com/rstudio/cheatsheets/blob/main/sf.pdf) for some examples). ```{r setup} +# package dependencies library(densityarea) library(dplyr) -library(tidyr) library(purrr) -library(stringr) - library(sf) +``` +```{r setup2, eval=FALSE} +# package suggests +library(tidyr) +library(stringr) library(ggplot2) ``` +```{r include=F} +tidyr_inst <- require(tidyr) +stringr_inst <- require(stringr) +ggplot2_inst <- require(ggplot2) +forcats_inst <- require(forcats) + +all_suggest <- all(c(tidyr_inst, stringr_inst, ggplot2_inst, forcats_inst)) +``` + ## Density polygons as simple features As a first example, we'll estimate how much different data clusters overlap in the `s01` dataset. @@ -83,7 +95,7 @@ vowel_polygons We can plot these directly by using the `sf::geom_sf()` geom for ggplot2. -```{r fig.width=5, fig.height=5, out.width="80%", fig.align='center'} +```{r, eval = ggplot2_inst, fig.width=5, fig.height=5, out.width="80%", fig.align='center'} ggplot(vowel_polygons) + geom_sf( aes(fill = plt_vclass), @@ -104,7 +116,7 @@ vowel_polygons |> vowel_polygons ``` -```{r fig.width=5, fig.height=5, out.width="80%", fig.align='center'} +```{r, eval=ggplot2_inst, fig.width=5, fig.height=5, out.width="80%", fig.align='center'} ggplot(vowel_polygons) + geom_sf( aes(fill = area), @@ -115,7 +127,7 @@ ggplot(vowel_polygons) + Or, we can get the polygon centroids and plot them. -```{r fig.width=5, fig.height=5, out.width="80%", fig.align='center'} +```{r, eval=ggplot2_inst, fig.width=5, fig.height=5, out.width="80%", fig.align='center'} vowel_polygons |> st_centroid() |> ggplot()+ @@ -142,7 +154,7 @@ vowel_intersections This data frame contains a polygon for each unique intersection of the input polygons, with a new `n.overlaps` column. -```{r fig.width=5, fig.height=5, out.width="80%", fig.align='center'} +```{r, eval=ggplot2_inst, fig.width=5, fig.height=5, out.width="80%", fig.align='center'} ggplot(vowel_intersections) + geom_sf( aes(fill = n.overlaps) @@ -152,13 +164,19 @@ ggplot(vowel_intersections) + The labels of the new overlapping regions aren't very informative, but we can create some new labels by using the indices in the `origins` column. -```{r} +```{r, eval=stringr_inst, echo=stringr_inst} new_label <- function(indices, labels){ str_c(labels[indices], collapse = "~") } ``` +```{r, eval=!stringr_inst, echo=!stringr_inst} +new_label <- function(indicies, labels){ + paste0(labels[indicies], collapse = "~") +} +``` + ```{r} vowel_intersections |> mutate( @@ -174,7 +192,7 @@ vowel_intersections |> vowel_intersections ``` -```{r fig.width=5, fig.height=5, out.width="80%", fig.align='center'} +```{r eval = ggplot2_inst, fig.width=5, fig.height=5, out.width="80%", fig.align='center'} ggplot(vowel_intersections)+ geom_sf( aes(fill = groups) @@ -184,7 +202,7 @@ ggplot(vowel_intersections)+ We can also calculate the areas of these new polygons, and compare them to the original areas (which have been preserved in `areas`. -```{r fig.width=5, fig.height=3, out.width="80%", fig.align='center'} +```{r eval=ggplot2_inst, fig.width=5, fig.height=3, out.width="80%", fig.align='center'} vowel_intersections |> mutate( group_area = st_area(geometry), @@ -204,6 +222,9 @@ There are also a number of spatial filters and merges that can be used interesti ```{r} library(sfheaders) +``` + +```{r, eval=F} library(forcats) ``` @@ -219,7 +240,7 @@ s01 |> s01_sf ``` -```{r fig.width=5, fig.height=5, out.width="80%", fig.align='center'} +```{r eval=ggplot2_inst, fig.width=5, fig.height=5, out.width="80%", fig.align='center'} s01_sf |> ggplot()+ geom_sf() @@ -250,7 +271,7 @@ s01_sf |> covered_by_iy ``` -```{r fig.width=5, fig.height=5, out.width="80%", fig.align='center'} +```{r, eval=all_suggest, fig.width=5, fig.height=5, out.width="80%", fig.align='center'} covered_by_iy |> mutate(plt_vclass = plt_vclass |> fct_infreq() |> @@ -263,7 +284,7 @@ covered_by_iy |> Obviously, the 80% probability density area for `iy` is not a homogeneous region. -```{r fig.width=5, fig.height=3, out.width="80%", fig.align='center'} +```{r eval=all_suggest, fig.width=5, fig.height=3, out.width="80%", fig.align='center'} covered_by_iy |> mutate(plt_vclass = plt_vclass |> fct_infreq() |> @@ -309,7 +330,7 @@ s01 |> There are 5 probability level polygons for each vowel category in `vowel_probs`. We join the random vowel's data onto this set of polygons with `st_join()`. -```{r} +```{r, eval=tidyr_inst, echo=tidyr_inst} vowel_probs |> st_join( rand_vowel, @@ -319,9 +340,21 @@ vowel_probs |> vowel_within ``` +```{r, eval=!tidyr_inst, echo=!tidyr_inst} +vowel_probs |> + st_join( + rand_vowel, + .predicate = st_covers + ) |> + filter( + !is.na(plt_vclass.y) + ) -> + vowel_within +``` + Now, for each vowel category in this new data frame, let's get the *smallest* probability polygon (i.e. where the random point is closest to the center probability mass). -```{r} +```{r, eval=forcats_inst, echo = forcats_inst} vowel_within |> group_by(plt_vclass.x) |> filter(prob == min(prob)) |> @@ -330,7 +363,17 @@ vowel_within |> vowel_min_prob ``` -```{r fig.width=5, fig.height = 5, out.width="80%"} +```{r, eval=!forcats_inst, echo = !forcats_inst} +vowel_within |> + group_by(plt_vclass.x) |> + filter(prob == min(prob)) |> + ungroup() |> + mutate(plt_vclass = reorder(factor(plt_vclass.x), + prob)) -> + vowel_min_prob +``` + +```{r eval = ggplot2_inst, fig.width=5, fig.height = 5, out.width="80%"} vowel_min_prob |> ggplot()+ geom_sf(aes(fill = prob)) +