Skip to content

Commit

Permalink
merge for dev
Browse files Browse the repository at this point in the history
Merge branch 'main' of https://github.com/JoFrhwld/densityarea

# Conflicts:
#	DESCRIPTION
#	usethis_hist.R
  • Loading branch information
JoFrhwld committed Oct 2, 2023
2 parents 4d45e0c + b518af7 commit c4c4dc8
Show file tree
Hide file tree
Showing 18 changed files with 471 additions and 164 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ usethis_hist.R
^_pkgdown\.yml$
^docs$
^pkgdown$
^cran-comments\.md$
.DS_Store
^CRAN-SUBMISSION$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.Ruserdata
inst/doc
docs
.DS_Store
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# densityarea 0.1.0

* Initial CRAN submission.
4 changes: 2 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
21 changes: 21 additions & 0 deletions R/density_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ knitr::opts_chunk$set(

<!-- badges: start -->
[![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)
<!-- badges: end -->

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'*. <https://jamesotto852.github.io/ggdensity/,> <https://github.com/jamesotto852/ggdensity/.>
[^1]: Otto J, Kahle D (2023). *ggdensity: Interpretable Bivariate Density Visualization with 'ggplot2'*. <https://jamesotto852.github.io/ggdensity/> <https://github.com/jamesotto852/ggdensity/>

```{r}
#| fig-width: 4
Expand All @@ -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")
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<!-- badges: start -->

[![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)
<!-- badges: end -->

The package `{ggdensity}`[^1] allows for plotting interpretable
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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’*.
<https://jamesotto852.github.io/ggdensity/,>
<https://github.com/jamesotto852/ggdensity/.>
<https://jamesotto852.github.io/ggdensity/>
<https://github.com/jamesotto852/ggdensity/>
41 changes: 41 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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

30 changes: 18 additions & 12 deletions inst/examples/density_area_example.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
library(densityarea)
library(ggplot2)
library(dplyr)
library(tidyr)
library(sf)

ggplot2_inst <- require(ggplot2)

# basic usage

set.seed(10)
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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))
}
92 changes: 51 additions & 41 deletions inst/examples/density_polygon_example.R
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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,
Expand All @@ -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

Expand All @@ -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 |>
Expand All @@ -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
}
Loading

0 comments on commit c4c4dc8

Please sign in to comment.