Skip to content

Commit

Permalink
fixing stat_fill_labels and stat_stack_labels
Browse files Browse the repository at this point in the history
to be compatible with last version of ggplot2
  • Loading branch information
larmarange committed Nov 30, 2016
1 parent 755284c commit 74af35d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: JLutils
Type: Package
Title: Collection of R functions
Version: 1.10.1
Date: 2016-08-24
Version: 1.11.0
Date: 2016-11-30
Author: Joseph Larmarange <joseph@larmarange.net>
Maintainer: Joseph Larmarange <joseph@larmarange.net>
Description: A collection of diverse R functions who don't fit (yet?) in another
Expand All @@ -11,7 +11,7 @@ License: GPL (>= 3)
URL: https://github.com/larmarange/JLutils
Encoding: UTF-8
Depends:
ggplot2,
ggplot2 (>= 2.2.0),
plyr
Suggests:
TraMineR,
Expand Down
8 changes: 6 additions & 2 deletions R/stat_fill_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ StatFillLabels <- ggproto(
plyr::ddply(
data, "x", plyr::mutate,
prop = count/sum(count),
cumprop = cumsum(count)/sum(count),
ylabel = (cumsum(count) - count / 2)/sum(count),
cumprop = .inv_cumsum(count)/sum(count),
ylabel = (.inv_cumsum(count) - count / 2)/sum(count),
na.rm = TRUE
)
},
default_aes = aes(y = ..ylabel.., label = paste0(round(100 * ..prop.., digits =1), "%"))
)

.inv_cumsum <- function(x) {
sum(x) - cumsum(x) +x
}
4 changes: 2 additions & 2 deletions R/stat_stack_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ StatStackLabels <- ggproto(
data <- do.call(plyr::rbind.fill, stats)
plyr::ddply(
data, "x", plyr::mutate,
cumcount = cumsum(count),
ylabel = cumsum(count) - count / 2,
cumcount = .inv_cumsum(count),
ylabel = .inv_cumsum(count) - count / 2,
na.rm = TRUE
)
},
Expand Down

0 comments on commit 74af35d

Please sign in to comment.