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