Expose plot axes labels in R

This commit is contained in:
Ben Letham 2017-02-26 17:31:34 +02:00
parent 4c9ad937d3
commit afc2392f91
2 changed files with 12 additions and 3 deletions

View file

@ -876,6 +876,8 @@ df_for_plotting <- function(m, fcst) {
#' @param fcst Data frame returned by predict(m, df). #' @param fcst Data frame returned by predict(m, df).
#' @param uncertainty Boolean indicating if the uncertainty interval for yhat #' @param uncertainty Boolean indicating if the uncertainty interval for yhat
#' should be plotted. Must be present in fcst as yhat_lower and yhat_upper. #' 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 #' @param ... additional arguments
#' #'
#' @return A ggplot2 plot. #' @return A ggplot2 plot.
@ -891,10 +893,12 @@ df_for_plotting <- function(m, fcst) {
#' } #' }
#' #'
#' @export #' @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) df <- df_for_plotting(x, fcst)
forecast.color <- "#0072B2" 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)) { if (exists('cap', where = df)) {
gg <- gg + ggplot2::geom_line( gg <- gg + ggplot2::geom_line(
ggplot2::aes(y = cap), linetype = 'dashed', na.rm = TRUE) ggplot2::aes(y = cap), linetype = 'dashed', na.rm = TRUE)

View file

@ -4,7 +4,8 @@
\alias{plot.prophet} \alias{plot.prophet}
\title{Plot the prophet forecast.} \title{Plot the prophet forecast.}
\usage{ \usage{
\method{plot}{prophet}(x, fcst, uncertainty = TRUE, ...) \method{plot}{prophet}(x, fcst, uncertainty = TRUE, xlabel = "ds",
ylabel = "y", ...)
} }
\arguments{ \arguments{
\item{x}{Prophet object.} \item{x}{Prophet object.}
@ -14,6 +15,10 @@
\item{uncertainty}{Boolean indicating if the uncertainty interval for yhat \item{uncertainty}{Boolean indicating if the uncertainty interval for yhat
should be plotted. Must be present in fcst as yhat_lower and yhat_upper.} 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} \item{...}{additional arguments}
} }
\value{ \value{