Skip to content

Commit

Permalink
Switch to ggplot 3.3 after_stat and 3.4 dropped_aes (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Jan 5, 2023
1 parent ab841c3 commit 205037b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 30 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: deps
uses: r-lib/ghactions/actions/install-deps@v0.4.1
- name: checks
uses: r-lib/ghactions/actions/check@v0.4.1
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache-version: 2
extra-packages: any::rcmdcheck
needs: check
- uses: r-lib/actions/check-r-package@v2
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ggplot.multistats
Title: Multiple Summary Statistics for Binned Stats/Geometries
Version: 1.0.0
Authors@R:
Authors@R:
person(given = "Philipp",
family = "Angerer",
role = c("aut", "cre"),
Expand All @@ -17,5 +17,5 @@ BugReports: https://github.com/flying-sheep/ggplot.multistats/issues
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports: methods, rlang, scales, hexbin, ggplot2
RoxygenNote: 7.0.0
Imports: methods, rlang, scales, hexbin, ggplot2 (>= 3.3.0)
RoxygenNote: 7.2.3
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU General Public License
==========================

_Version 3, 29 June 2007_
_Version 3, 29 June 2007_
_Copyright © 2007 Free Software Foundation, Inc. &lt;<http://fsf.org/>&gt;_

Everyone is permitted to copy and distribute verbatim copies of this license
Expand Down
11 changes: 6 additions & 5 deletions R/stat_summaries_hex.r
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#' library(ggplot2)
#' # Define the variable used for the stats using z
#' ggplot_base <- ggplot(iris, aes(Sepal.Width, Sepal.Length, z = Petal.Width))
#' # The default is creating `stat(value)` containing the mean
#' ggplot_base + stat_summaries_hex(aes(fill = stat(value)), bins = 5)
#' # The default is creating `after_stat(value)` containing the mean
#' ggplot_base + stat_summaries_hex(aes(fill = after_stat(value)), bins = 5)
#' # but you can specify your own stats
#' ggplot_base + stat_summaries_hex(
#' aes(fill = stat(median), alpha = stat(n)),
#' aes(fill = after_stat(median), alpha = after_stat(n)),
#' funs = c('median', n = 'length'),
#' bins = 5)
#'
Expand Down Expand Up @@ -63,8 +63,9 @@ stat_summaries_hex <- function(
StatSummariesHex <- ggproto(
'StatSummariesHex',
Stat,
#default_aes = aes(fill = stat(value)),
#default_aes = aes(fill = after_stat(value)),
required_aes = c('x', 'y', 'z'),
dropped_aes = c('z'),
compute_group = function(
data, scales,
binwidth = NULL, bins = 30,
Expand All @@ -77,7 +78,7 @@ StatSummariesHex <- ggproto(
funs <- as.list(normalize_function_list(funs)) # if it was no list before, adding a function makes it one
funs$`_dummy` <- function(x) 1 # hexBinSummarise ruins our day if we have less than two items in the list
idx_dummy <- names(funs) %in% '_dummy'
if (sum(idx_dummy) > 1L) stop('You cannot name a function `_dummy_, sorry.')
if (sum(idx_dummy) > 1L) stop('You cannot name a function `_dummy`, sorry.')

fun <- function(x) sapply(funs, exec, x, simplify = FALSE)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ devtools::install_github('flying-sheep/ggplot.multistats')
Example
-------
Specify a summary variable using the `z` aesthetic
and specify a list of `funs` to provide `stat`s for you:
and specify a list of `funs` to provide `after_stat`s for you:

```r
library(ggplot2)
library(ggplot.multistats)

ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
stat_summaries_hex(
aes(z = Petal.Width, fill = stat(median), alpha = stat(n)),
aes(z = Petal.Width, fill = after_stat(median), alpha = after_stat(n)),
funs = c('median', n = 'length'),
bins = 5
)
Expand Down
36 changes: 21 additions & 15 deletions man/stat_summaries_hex.Rd

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

0 comments on commit 205037b

Please sign in to comment.