瀏覽代碼

Expose plot axes labels in R

Ben Letham 8 年之前
父節點
當前提交
afc2392f91
共有 2 個文件被更改,包括 12 次插入3 次删除
  1. 6 2
      R/R/prophet.R
  2. 6 1
      R/man/plot.prophet.Rd

+ 6 - 2
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)

+ 6 - 1
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{