Skip to content

Commit 82ebc34

Browse files
committed
plot() training history fix:
When using base graphics to plot a history with only a single metric, correctly calculate margins to display axis labels. This updates the `if else` chain to a series of `if` expressions, allowing for a plot to be both a `bottom_plot` and a `top_plot`.
1 parent ca82128 commit 82ebc34

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

R/history.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ plot.keras_training_history <- function(x, y, metrics = NULL, method = c("auto",
145145
# adjust margins
146146
top_plot <- i == 1
147147
bottom_plot <- i == length(metrics)
148+
149+
mar <- c(1.5, 3, 0.5, 1.5)
148150
if (top_plot)
149-
par(mar = c(1.5, 3, 1.5, 1.5))
150-
else if (bottom_plot)
151-
par(mar = c(2.5, 3, .5, 1.5))
152-
else
153-
par(mar = c(1.5, 3, .5, 1.5))
151+
mar[3] %<>% `+`(1)
152+
if (bottom_plot)
153+
mar[1] %<>% `+`(1)
154+
par(mar = mar)
154155

155156
# select data for current panel
156157
df2 <- df[df$metric == metric, ]

0 commit comments

Comments
 (0)