mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-06-03 23:49:47 +00:00
used regex to format the name variable for plotting holiday components (#1766)
* used regex to format the `name`
Removes all singlequotes (') and doublequotes (") in the `name` variable
and replaces all whitespace with an underscore. Now, `ggplot2::aes_string()` can handle a column
name like `New Year's Day`.
* Used backticks in the `name` variable instead of regular expressions
Essentially, I escaped the string `name` with backticks so that
`ggplot2::geom_line()` and `ggplot2::ggplot()` functions can use any
arbitrary input.
This commit is contained in:
parent
fdb6b36506
commit
73b53658e1
1 changed files with 11 additions and 2 deletions
13
R/R/plot.R
13
R/R/plot.R
|
|
@ -177,8 +177,17 @@ prophet_plot_components <- function(
|
|||
plot_forecast_component <- function(
|
||||
m, fcst, name, uncertainty = TRUE, plot_cap = FALSE
|
||||
) {
|
||||
|
||||
wrapped.name <- paste0("`", name, "`")
|
||||
|
||||
lower.name <- paste0(name, '_lower')
|
||||
lower.name <- paste0("`", lower.name, "`")
|
||||
|
||||
upper.name <- paste0(name, '_upper')
|
||||
upper.name <- paste0("`", upper.name, "`")
|
||||
|
||||
gg.comp <- ggplot2::ggplot(
|
||||
fcst, ggplot2::aes_string(x = 'ds', y = name, group = 1)) +
|
||||
fcst, ggplot2::aes_string(x = 'ds', y = wrapped.name, group = 1)) +
|
||||
ggplot2::geom_line(color = "#0072B2", na.rm = TRUE)
|
||||
if (exists('cap', where = fcst) && plot_cap) {
|
||||
gg.comp <- gg.comp + ggplot2::geom_line(
|
||||
|
|
@ -192,7 +201,7 @@ plot_forecast_component <- function(
|
|||
gg.comp <- gg.comp +
|
||||
ggplot2::geom_ribbon(
|
||||
ggplot2::aes_string(
|
||||
ymin = paste0(name, '_lower'), ymax = paste0(name, '_upper')
|
||||
ymin = lower.name, ymax = upper.name
|
||||
),
|
||||
alpha = 0.2,
|
||||
fill = "#0072B2",
|
||||
|
|
|
|||
Loading…
Reference in a new issue