Skip to content

Commit

Permalink
fix issue with stacked histogram (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
vandenman authored Dec 6, 2024
1 parent 797e38a commit c73a76c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions R/jaspHistogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,19 @@ jaspHistogram <- function(
position = histogramPosition
)

# for each groupingvariable, bin by breaks and find the largest count
temp <- do.call(rbind, tapply(x, groupingVariable, function(subset) {
h <- graphics::hist(subset, plot = FALSE, breaks = binWidthType)
c(counts = max(h[["counts"]]), density = max(h[["density"]]))
}))
maxCounts <- max(temp[, "counts"])
maxDensity <- max(temp[, "density"])
if (identical(histogramPosition, "stack") || inherits(histogramPosition, "PositionStack")) {
# for a stacked figure we base maxCounts and maxDensity on the ungrouped data
maxCounts <- h[["counts"]]
maxDensity <- h[["density"]]
} else {
# for each groupingvariable, bin by breaks and find the largest count
temp <- do.call(rbind, tapply(x, groupingVariable, function(subset) {
h <- graphics::hist(subset, plot = FALSE, breaks = binWidthType)
c(counts = max(h[["counts"]]), density = max(h[["density"]]))
}))
maxCounts <- max(temp[, "counts"])
maxDensity <- max(temp[, "density"])
}

} else {
dataHistogram <- data.frame(x = x)
Expand Down

0 comments on commit c73a76c

Please sign in to comment.