From aabd558c8bd87529bfa63e457650071ec6249730 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 5 Apr 2021 12:57:09 +0200 Subject: [PATCH 1/2] fix plot predictions when no truth is available --- R/plot.R | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/R/plot.R b/R/plot.R index 1f0231b6f..0e50c98df 100644 --- a/R/plot.R +++ b/R/plot.R @@ -763,17 +763,19 @@ plot_predictions <- function(data = NULL, } # add true_values - plot <- plot + - ggplot2::labs(x = xlab, y = ylab) - - plot <- plot + - ggplot2::geom_point(data = truth_data, - ggplot2::aes(y = true_value, colour = "actual"), - size = 0.5) + - ggplot2::geom_line(data = truth_data, - ggplot2::aes(y = true_value, colour = "actual"), - lwd = 0.2) - return(plot) + if (nrow(truth_data) > 0) { + plot <- plot + + ggplot2::labs(x = xlab, y = ylab) + + plot <- plot + + ggplot2::geom_point(data = truth_data, + ggplot2::aes(y = true_value, colour = "actual"), + size = 0.5) + + ggplot2::geom_line(data = truth_data, + ggplot2::aes(y = true_value, colour = "actual"), + lwd = 0.2) + return(plot) + } } From c5a6c26f2e44fbd893a4fbcc87de8bd54412a63a Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 5 Apr 2021 13:06:00 +0200 Subject: [PATCH 2/2] move return statement to correct place --- R/plot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/plot.R b/R/plot.R index 0e50c98df..7efdb863b 100644 --- a/R/plot.R +++ b/R/plot.R @@ -774,8 +774,8 @@ plot_predictions <- function(data = NULL, ggplot2::geom_line(data = truth_data, ggplot2::aes(y = true_value, colour = "actual"), lwd = 0.2) - return(plot) } + return(plot) }