Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where grouped boxplots and violin plots were variable width… #173

Merged
merged 3 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ggExtra
Title: Add Marginal Histograms to 'ggplot2', and More 'ggplot2' Enhancements
Version: 0.10.0
Version: 0.10.0.9000
Authors@R: c(
person("Dean", "Attali", , "[email protected]", role = c("aut", "cre")),
person("Christopher", "Baker", , "[email protected]", role = "aut")
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ggExtra 0.10.9000

2023-01-27

- Fixed issue where grouped boxplots and violin plots were variable widths (#173)

# ggExtra 0.10.0

2022-03-22
Expand Down
25 changes: 8 additions & 17 deletions R/ggMarginal-MarginalPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ MarginalPlot <- R6::R6Class("MarginalPlot",
scatDF$x <- scatDF$y
}

scatDF$y <- scatDF$x
# We never want to actually use the y aesthetic when creating the marginal
# plots, but geom_violin requires it. Also note that, in order to make the
# widths of violin and boxplots the same in the marginal plots, we need a
# constant y.
scatDF$y <- 1
scatDF[, c("x", "y", "fill", "colour", "group")]
},

Expand Down Expand Up @@ -246,15 +250,8 @@ MarginalPlot <- R6::R6Class("MarginalPlot",

addLimits = function(margThemed) {
limits <- private$getLimits()
# for plots with y aes we have to use scale_y_continuous instead of
# scale_x_continuous.
if (self$type %in% c("boxplot", "violin")) {
margThemed +
ggplot2::scale_y_continuous(limits = limits, oob = scales::squish)
} else {
margThemed +
ggplot2::scale_x_continuous(limits = limits, oob = scales::squish)
}
margThemed +
ggplot2::scale_x_continuous(limits = limits, oob = scales::squish)
},

getPanelScale = function(marg) {
Expand All @@ -275,13 +272,7 @@ MarginalPlot <- R6::R6Class("MarginalPlot",
},

needsFlip = function() {
# If the marginal plot is: (for the x margin (top) and is a boxplot) or
# (for the y margin (right) and is not a boxplot),
# ... then have to flip
topAndBoxP <- self$marg == "x" && self$type %in% c("boxplot", "violin")
rightAndNonBoxP <-
self$marg == "y" && !(self$type %in% c("boxplot", "violin"))
topAndBoxP || rightAndNonBoxP
self$marg == "y"
},

# Get the axis range of the x or y axis of the given ggplot build object
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading