@@ -58,40 +58,23 @@ plot_residual_density <- function(object, ..., variable = "") {
58
58
model_count <- nlevels(df $ `_label_` )
59
59
df $ `_ord_` <- paste(rev(as.numeric(df $ `_label_` )), df $ `_label_` )
60
60
61
- if (! is.null(variable )) {
62
- split <- FALSE
63
- if (variable != " " ) split <- TRUE
64
- }
61
+ split <- TRUE
65
62
66
- # set value for label of the X axis
67
- if (is.null(variable )) {
68
- lab <- " observations"
69
- split <- TRUE
70
- } else if (variable == " _y_" ) {
71
- lab <- " target variable"
72
- } else if (variable == " _y_hat_" ) {
73
- lab <- " actual response"
74
- } else {
75
- lab <- as.character(df $ `_variable_` [1 ])
63
+ if (! is.null(variable )) {
64
+ if (variable == " " ) split <- FALSE
76
65
}
77
66
78
- levels( df $ `_div_` ) <- gsub( " \\ s.+ \\ s| \\ s \\ s " , paste0( " " , lab , " " ), levels( df $ `_div_` ))
67
+ var_split <- " `_label_` "
79
68
80
69
# arguments differ depending on splitting or not
81
70
if (split == TRUE ) {
82
- var_split <- " `_label_`"
83
71
colours <- theme_drwhy_colors(nlevels(df $ `_div_` ))
84
72
legend_pos <- " bottom"
85
- # if (model_count == 1) legend_pos <- "none"
86
73
legend_just <- " center"
87
- split_by <- unique(df $ `_label_` )
88
- } else if (split == FALSE ) {
89
- var_split <- " `_label_`"
74
+ } else {
90
75
colours <- theme_drwhy_colors(model_count )
91
76
legend_pos <- " top"
92
77
legend_just <- c(1 , 0 )
93
- # if (model_count == 1) legend_pos <- "none"
94
- split_by <- unique(df $ `_label_` )
95
78
}
96
79
97
80
if (model_count == 1 ) legend_pos <- " none"
@@ -102,7 +85,7 @@ plot_residual_density <- function(object, ..., variable = "") {
102
85
geom_vline(xintercept = 0 , colour = " darkgrey" ) +
103
86
annotate(" segment" , x = - Inf , xend = Inf , y = - Inf , yend = - Inf , colour = " #371ea3" ) +
104
87
scale_color_manual(values = colours ) +
105
- scale_fill_manual(values = colours , breaks = split_by ) +
88
+ scale_fill_manual(values = colours , breaks = unique( df $ `_label_` ) ) +
106
89
guides(fill = guide_legend(override.aes = list (alpha = 0.5 ))) +
107
90
theme_drwhy() +
108
91
theme(axis.line.x = element_line(color = " #371ea3" ),
0 commit comments