Skip to content

Commit eec7028

Browse files
authored
fix: Fix the bug in heatmap plot (#58)
* Fix the bug in heatmap plot
1 parent 3ce74b3 commit eec7028

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ jobs:
3535
- {os: windows-latest, r: '4.1'}
3636
- {os: windows-latest, r: '4.0'}
3737
- {os: windows-latest, r: '3.6'}
38-
- {os: windows-latest, r: '3.5'}
3938
- {os: macOS-latest, r: '4.1'}
4039
- {os: macOS-latest, r: '4.0'}
41-
- {os: macOS-latest, r: '3.6'}
4240
- {os: ubuntu-18.04, r: '4.1', vdiffr: true, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
4341
- {os: ubuntu-18.04, r: '4.0', vdiffr: true, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
4442
- {os: ubuntu-18.04, r: '3.6', vdiffr: true, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
45-
- {os: ubuntu-18.04, r: '3.5', vdiffr: true, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
46-
4743

4844
env:
4945
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: fairmodels
22
Type: Package
33
Title: Flexible Tool for Bias Detection, Visualization, and Mitigation
4-
Version: 1.2.1
4+
Version: 1.2.2
55
Authors@R:
66
c(person("Jakub", "Wiśniewski", role = c("aut", "cre"),
77
email = "[email protected]"),
@@ -28,7 +28,7 @@ Suggests:
2828
spelling,
2929
ggdendro,
3030
ggrepel,
31-
RoxygenNote: 7.1.1.9001
31+
RoxygenNote: 7.3.3
3232
VignetteBuilder: knitr
3333
URL: https://fairmodels.drwhy.ai/
3434
BugReports: https://github.com/ModelOriented/fairmodels/issues

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# fairmodels 1.2.2
2+
* changed ifelse to if else statement in `fairness_heatmap` as per https://github.com/ModelOriented/fairmodels/issues/57
3+
14
# fairmodels 1.2.1
25
* changed link to *codecov* in `README.md`
36
* changed `class(x) == 'fairness_regression_object` to `inherits(x, "fairness_regression_object")` in `plot_density.R` according to CRAN comments

R/plot_fairness_heatmap.R

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#' @param flip_axis logical, whether to change axis with metrics on axis with models
1515
#' @param text_size numeric, size of text
1616
#'
17-
#' @return list of \code{ggplot2} objects
17+
#' @return ggplot object with the combined heatmap and dendograms
1818
#'
1919
#' @import patchwork
2020
#' @import ggplot2
@@ -166,10 +166,12 @@ plot.fairness_heatmap <- function(x, ...,
166166
data$score <- as.numeric(data$score)
167167

168168
# heatmap
169-
ifelse(!flip_axis,
170-
p <- ggplot(data, aes(parity_loss_metric, model, fill = score)),
169+
if(!flip_axis) {
170+
p <- ggplot(data, aes(parity_loss_metric, model, fill = score))
171+
172+
} else {
171173
p <- ggplot(data, aes(model, parity_loss_metric, fill = score))
172-
)
174+
}
173175

174176
heatmap <- p + geom_tile(
175177
colour = "white",
@@ -199,15 +201,17 @@ plot.fairness_heatmap <- function(x, ...,
199201
)
200202
}
201203

202-
ifelse(!flip_axis,
203-
dendogram_right <- dendogram_model + coord_flip(),
204+
if (!flip_axis) {
205+
dendogram_right <- dendogram_model + coord_flip()
206+
} else {
204207
dendogram_right <- dendogram_metric + coord_flip()
205-
)
208+
}
206209

207-
ifelse(!flip_axis,
208-
dendogram_top <- dendogram_metric,
210+
if (!flip_axis) {
211+
dendogram_top <- dendogram_metric
212+
} else {
209213
dendogram_top <- dendogram_model
210-
)
214+
}
211215

212216
# adding title
213217
dendogram_top <- dendogram_top +
@@ -216,11 +220,13 @@ plot.fairness_heatmap <- function(x, ...,
216220
)
217221

218222
# Plot layout
219-
dendogram_top + plot_spacer() +
223+
final_plot <- (dendogram_top + plot_spacer() +
220224
heatmap + dendogram_right +
221225
patchwork::plot_layout(
222226
ncol = 2,
223227
widths = c(1, 0.4),
224228
heights = c(0.4, 1)
225-
)
229+
))
230+
231+
return(final_plot)
226232
}

0 commit comments

Comments
 (0)