facebookexperimental / Robyn

Robyn is an experimental, AI/ML-powered and open sourced Marketing Mix Modeling (MMM) package from Meta Marketing Science. Our mission is to democratise modeling knowledge, inspire the industry through innovation, reduce human bias in the modeling process & build a strong open source marketing science community.
https://facebookexperimental.github.io/Robyn/
MIT License
1.07k stars 323 forks source link

One-pager plots are cut-off so not all information is shown (missing legend) #986

Open NumesSanguis opened 1 month ago

NumesSanguis commented 1 month ago

Project Robyn

Describe issue

After generating the one-pager output PNG with:

OutputCollect <- robyn_outputs(
  InputCollect, OutputModels,
  pareto_fronts = "auto", # automatically pick how many pareto-fronts to fill min_candidates (100)
  # min_candidates = 100, # top pareto models for clustering. Default to 100
  # calibration_constraint = 0.1, # range c(0.01, 0.1) & default at 0.1
  csv_out = "pareto", # "pareto", "all", or NULL (for none)
  clusters = TRUE, # Set to TRUE to cluster similar models by ROAS. See ?robyn_clusters
  export = create_files, # this will create files locally
  plot_folder = robyn_directory, # path for plots exports and files creation
  plot_pareto = create_files # Set to FALSE to deactivate plotting and saving model one-pagers
)

Some of the text is cut-off (maybe the font size is too big)? As for the "Response Curves and Mean Spends by Channel", which line is which media is not even shown. See this crop of the one-pager: 5_227_9_crop

Provide reproducible example

This seem to be related to R output only, so it seems to unrelated to the calculations of the model.

My first thought was that my names for each variable was too long, but I reduced it to maximum 9 characters, which is shorter than (intercept). Still the problem persisted.

Environment & Robyn version

Make sure you're using the latest Robyn version before you post an issue.

Workaround

Is it possible to output each figure individually as a PNG as well, besides only all in 1 page? That would be easier for incorporating it in presentations.

NumesSanguis commented 1 month ago

It seems likely that it is a font issue. When trying to show a plot, it cannot find the font Arial Narrow:

## 1. IMPORTANT: set plot = TRUE to create example plots for adstock & saturation
## hyperparameters and their influence in curve transformation.
plot_adstock(plot = TRUE)  # FALSE
plot_saturation(plot = TRUE)  # FALSE

Gives the error:

Warning message in .font_global(font, quiet = FALSE, ...):
“Font(s) 'Arial Narrow' not installed, with other name, or can't be found”
Warning message in geom_text(aes(x = max(.data$x), y = 0.5, vjust = -0.5, hjust = 1, :
“All aesthetics have length 1, but the data has 900 rows.
ℹ Please consider using `annotate()` or provide this layer with data containing
  a single row.”

I documented my attempts to install this font in this issue: https://github.com/facebookexperimental/Robyn/issues/973#issuecomment-2141129461 but without success so far.

kevindotmcdonnellatartefactdotcom commented 3 weeks ago

It is possible to plot all of the plots individually - there is some code showing this in the demo file. I have copied the most relevant lines below, but you may need to check the demo depending on your own naming conventions etc.

myOnePager <- robyn_onepagers(InputCollect, OutputCollect, select_model, export = FALSE)

# To check each of the one-pager's plots
# myOnePager[[select_model]]$patches$plots[[1]]
NumesSanguis commented 3 weeks ago

Thank you for pointing that out @kevindotmcdonnellatartefactdotcom ! Seems I missed that somehow.

The output of myOnePager[[robyn_model]]$patches$plots[[4]] actually gives me both the plot "Response Curves and Mean Spend" as well as the plot "Fitted vs. Residual". I was able to get a single plot by appending with [[1]] and I could save it with ggplot2:

myplot <- myOnePager[[robyn_model]]$patches$plots[[4]][[1]]
ggplot2::ggsave(
    plot = myplot,
    filename = paste0(robyn_directory, robyn_model, "_response-curves.png"),
    width = 8,
    height = 5,
    dpi = 200
)

This does give me a Legend. It seems this is not the first time this issue came up:

Related discussions: