From afc2392f919345d555b8e81e0607e6362b128c9e Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Sun, 26 Feb 2017 17:31:34 +0200 Subject: [PATCH] Expose plot axes labels in R --- R/R/prophet.R | 8 ++++++-- R/man/plot.prophet.Rd | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/R/R/prophet.R b/R/R/prophet.R index 61df7c3..9af0836 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -876,6 +876,8 @@ df_for_plotting <- function(m, fcst) { #' @param fcst Data frame returned by predict(m, df). #' @param uncertainty Boolean indicating if the uncertainty interval for yhat #' should be plotted. Must be present in fcst as yhat_lower and yhat_upper. +#' @param xlabel Optional label for x-axis +#' @param ylabel Optional label for y-axis #' @param ... additional arguments #' #' @return A ggplot2 plot. @@ -891,10 +893,12 @@ df_for_plotting <- function(m, fcst) { #' } #' #' @export -plot.prophet <- function(x, fcst, uncertainty = TRUE, ...) { +plot.prophet <- function(x, fcst, uncertainty = TRUE, xlabel = 'ds', + ylabel = 'y', ...) { df <- df_for_plotting(x, fcst) forecast.color <- "#0072B2" - gg <- ggplot2::ggplot(df, ggplot2::aes(x = ds, y = y)) + gg <- ggplot2::ggplot(df, ggplot2::aes(x = ds, y = y)) + + ggplot2::labs(x = xlabel, y = ylabel) if (exists('cap', where = df)) { gg <- gg + ggplot2::geom_line( ggplot2::aes(y = cap), linetype = 'dashed', na.rm = TRUE) diff --git a/R/man/plot.prophet.Rd b/R/man/plot.prophet.Rd index 22bea8f..5862f34 100644 --- a/R/man/plot.prophet.Rd +++ b/R/man/plot.prophet.Rd @@ -4,7 +4,8 @@ \alias{plot.prophet} \title{Plot the prophet forecast.} \usage{ -\method{plot}{prophet}(x, fcst, uncertainty = TRUE, ...) +\method{plot}{prophet}(x, fcst, uncertainty = TRUE, xlabel = "ds", + ylabel = "y", ...) } \arguments{ \item{x}{Prophet object.} @@ -14,6 +15,10 @@ \item{uncertainty}{Boolean indicating if the uncertainty interval for yhat should be plotted. Must be present in fcst as yhat_lower and yhat_upper.} +\item{xlabel}{Optional label for x-axis} + +\item{ylabel}{Optional label for y-axis} + \item{...}{additional arguments} } \value{