Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmonize API #373

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Harmonize API #373

wants to merge 5 commits into from

Conversation

IndrajeetPatil
Copy link
Member

cf. easystats/easystats#434

  • Rename args to follow color_* pattern

@strengejacke
Copy link
Member

Looks good! Only conflict we have is that we have rope_alpha, but color_rope. It's difficult... :-/ @DominiqueMakowski Master of names, what do you think?

@DominiqueMakowski
Copy link
Member

Can change for alpha_rope, it is aligned with the mental process of "I want to change the alpha of the rope"

@strengejacke
Copy link
Member

So we (roughly) have the pattern aes_geom / aes_element...

@bwiernik
Copy link
Contributor

One potential consideration is that ggplot2 names these sorts or arguments/aesthetics like: *.color

https://github.com/tidyverse/ggplot2/blob/main/R/geom-boxplot.R

We don't use . in argument names ever, so I don't think we should use the "full" ggplot2 naming scheme. Given that, I don't think it makes much difference whether we match the part-first order of names ggplot2 uses vs the aesthetic-first order used in this PR. Personally, I like aesthetic-first better and think we should use it. Just wanted to flag that it is a divergence from how ggplot2 and some extension packages name their arguments.

@strengejacke
Copy link
Member

I don't think we cover this case here in our coding style guidelines: https://easystats.github.io/easystats/articles/conventions.html

@strengejacke
Copy link
Member

What about the alphas?

library(easystats)
easystats_args <- NULL
for (pkg in easystats::easystats_packages()) {
  fns <- ls(paste0("package:", pkg))
  rds_filepath <- file.path(find.package(pkg), "NAMESPACE")
  
  all_fns <- tryCatch(
    as.data.frame(read.table(rds_filepath)),
    error = function(e){
      NULL
    }
  )
  if (!is.null(all_fns)) {
    names(all_fns) <- "func"
    all_fns <- data_filter(all_fns, startsWith(all_fns$func, "S3method("))
    fn <- gsub("S3method\\((.*)\\)", "\\1", all_fns$func)
    fn <- gsub(",", ".", fn, fixed = TRUE)
    
    all_args <- NULL
    for (i in fn) {
      all_args <- c(all_args, formalArgs(getFromNamespace(i, pkg)))
    }
    
    easystats_args <- c(easystats_args, sort(unique(all_args)))
  }
}

grep("alpha", sort(unique(easystats_args)), value = TRUE)
#> [1] "alpha"            "dispersion_alpha" "dot_alpha"        "line_alpha"      
#> [5] "posteriors_alpha" "priors_alpha"     "rope_alpha"       "si_alpha"

Created on 2024-11-20 with reprex v2.1.1

@bwiernik
Copy link
Contributor

alpha should come first like other aesthetics

@bwiernik
Copy link
Contributor

(Those are all plotting parameters and not alpha as in significance right? I think we use "level" for the latter everywhere)

@bwiernik
Copy link
Contributor

I don't think we cover this case here in our coding style guidelines: https://easystats.github.io/easystats/articles/conventions.html

Let's add that to ensure consistency going forward

@strengejacke
Copy link
Member

(Those are all plotting parameters and not alpha as in significance right? I think we use "level" for the latter everywhere)

Yes, I think so.

@strengejacke
Copy link
Member

strengejacke commented Nov 20, 2024

library(easystats)
easystats_args <- NULL
for (pkg in easystats::easystats_packages()) {
  fns <- ls(paste0("package:", pkg))
  rds_filepath <- file.path(find.package(pkg), "NAMESPACE")
  
  # for some packages, read.table fails...
  all_fns <- tryCatch(
    as.data.frame(read.table(rds_filepath)),
    error = function(e){
      NULL
    }
  )
  if (!is.null(all_fns)) {
    names(all_fns) <- "func"
    all_fns <- data_filter(all_fns, startsWith(all_fns$func, "S3method("))
    fn <- gsub("S3method\\((.*)\\)", "\\1", all_fns$func)
    fn <- gsub(",", ".", fn, fixed = TRUE)
    
    all_args <- NULL
    for (i in fn) {
      fun_args <- formalArgs(getFromNamespace(i, pkg))
      all_args <- rbind(
        all_args,
        data.frame(args = fun_args, fun = i, pkg = pkg)
      )
    }
    easystats_args <- rbind(easystats_args, all_args)
  }
}

easystats_args[grepl("alpha", easystats_args$args, fixed = TRUE), ] |> export_table()
#> args             |                               fun | pkg
#> ----------------------------------------------------------
#> rope_alpha       |   plot.see_bayesfactor_parameters | see
#> rope_alpha       | plot.see_bayesfactor_savagedickey | see
#> alpha            |          plot.see_check_normality | see
#> dot_alpha        |          plot.see_check_normality | see
#> dot_alpha        |           plot.see_check_outliers | see
#> alpha            |          plot.see_check_residuals | see
#> dot_alpha        |          plot.see_check_residuals | see
#> rope_alpha       |         plot.see_equivalence_test | see
#> rope_alpha       |      plot.see_equivalence_test_df | see
#> rope_alpha       |      plot.see_equivalence_test_lm | see
#> priors_alpha     |         plot.see_estimate_density | see
#> posteriors_alpha |         plot.see_estimate_density | see
#> priors_alpha     |              plot.see_p_direction | see
#> line_alpha       |               plot.see_p_function | see
#> priors_alpha     |           plot.see_p_significance | see
#> posteriors_alpha |     plot.see_parameters_brms_meta | see
#> rope_alpha       |     plot.see_parameters_brms_meta | see
#> dispersion_alpha |  plot.see_parameters_distribution | see
#> posteriors_alpha |      plot.see_parameters_simulate | see
#> line_alpha       |     plot.see_performance_pp_check | see
#> alpha            |       plot.see_performance_simres | see
#> dot_alpha        |       plot.see_performance_simres | see
#> priors_alpha     |           plot.see_point_estimate | see
#> rope_alpha       |                     plot.see_rope | see
#> si_alpha         |                       plot.see_si | see
#> line_alpha       |    print.see_performance_pp_check | see

@strengejacke
Copy link
Member

And we have all the sizes... base_size is maybe ok to keep, but what about font_size?

library(easystats)
easystats_args <- NULL
for (pkg in easystats::easystats_packages()) {
  fns <- ls(paste0("package:", pkg))
  rds_filepath <- file.path(find.package(pkg), "NAMESPACE")
  
  all_fns <- tryCatch(
    as.data.frame(read.table(rds_filepath)),
    error = function(e){
      NULL
    }
  )
  if (!is.null(all_fns)) {
    names(all_fns) <- "func"
    all_fns <- data_filter(all_fns, startsWith(all_fns$func, "S3method("))
    fn <- gsub("S3method\\((.*)\\)", "\\1", all_fns$func)
    fn <- gsub(",", ".", fn, fixed = TRUE)
    
    all_args <- NULL
    for (i in fn) {
      fun_args <- formalArgs(getFromNamespace(i, pkg))
      all_args <- rbind(
        all_args,
        data.frame(args = fun_args, fun = i, pkg = pkg)
      )
    }
    easystats_args <- rbind(easystats_args, all_args)
  }
}

easystats_args[grepl("size", easystats_args$args, fixed = TRUE), ] |>
  data_filter(pkg %in% c("see", "parameters")) |> 
  export_table()
#> args            |                                 fun |        pkg
#> ------------------------------------------------------------------
#> font_size       |          display.compare_parameters | parameters
#> font_size       |        display.parameters_brms_meta | parameters
#> font_size       |            display.parameters_model | parameters
#> font_size       |         display.parameters_simulate | parameters
#> font_size       |       print_html.compare_parameters | parameters
#> font_size       |     print_html.parameters_brms_meta | parameters
#> font_size       |         print_html.parameters_model | parameters
#> font_size       |           print_html.parameters_sem | parameters
#> font_size       |      print_html.parameters_simulate | parameters
#> size_point      |     plot.see_bayesfactor_parameters |        see
#> size_point      |   plot.see_bayesfactor_savagedickey |        see
#> size_line       |           plot.see_binned_residuals |        see
#> size_point      |           plot.see_binned_residuals |        see
#> size_title      |           plot.see_binned_residuals |        see
#> size_axis_title |           plot.see_binned_residuals |        see
#> base_size       |           plot.see_binned_residuals |        see
#> size_point      |         plot.see_check_collinearity |        see
#> size_line       |         plot.see_check_collinearity |        see
#> size_title      |         plot.see_check_collinearity |        see
#> size_axis_title |         plot.see_check_collinearity |        see
#> base_size       |         plot.see_check_collinearity |        see
#> size_point      |                  plot.see_check_dag |        see
#> size_text       |                  plot.see_check_dag |        see
#> size_point      |         plot.see_check_distribution |        see
#> size_point      | plot.see_check_distribution_numeric |        see
#> size_point      |   plot.see_check_heteroscedasticity |        see
#> size_line       |   plot.see_check_heteroscedasticity |        see
#> size_title      |   plot.see_check_heteroscedasticity |        see
#> size_axis_title |   plot.see_check_heteroscedasticity |        see
#> base_size       |   plot.see_check_heteroscedasticity |        see
#> size_line       |            plot.see_check_normality |        see
#> size_point      |            plot.see_check_normality |        see
#> size_title      |            plot.see_check_normality |        see
#> size_axis_title |            plot.see_check_normality |        see
#> base_size       |            plot.see_check_normality |        see
#> size_text       |             plot.see_check_outliers |        see
#> size_line       |             plot.see_check_outliers |        see
#> size_title      |             plot.see_check_outliers |        see
#> size_axis_title |             plot.see_check_outliers |        see
#> base_size       |             plot.see_check_outliers |        see
#> size_line       |             plot.see_check_overdisp |        see
#> size_title      |             plot.see_check_overdisp |        see
#> size_axis_title |             plot.see_check_overdisp |        see
#> base_size       |             plot.see_check_overdisp |        see
#> size_line       |            plot.see_check_residuals |        see
#> size_point      |            plot.see_check_residuals |        see
#> size_title      |            plot.see_check_residuals |        see
#> size_axis_title |            plot.see_check_residuals |        see
#> base_size       |            plot.see_check_residuals |        see
#> size_point      |         plot.see_compare_parameters |        see
#> size_text       |         plot.see_compare_parameters |        see
#> size_line       |        plot.see_compare_performance |        see
#> size_point      |        plot.see_equivalence_test_lm |        see
#> size_line       |           plot.see_estimate_density |        see
#> size_point      |           plot.see_estimate_density |        see
#> size_line       |        plot.see_estimate_density_df |        see
#> size            |                 plot.see_n_clusters |        see
#> size            |                  plot.see_n_factors |        see
#> size_point      |                 plot.see_p_function |        see
#> size_line       |                 plot.see_p_function |        see
#> size_text       |                 plot.see_p_function |        see
#> size_point      |       plot.see_parameters_brms_meta |        see
#> size_line       |       plot.see_parameters_brms_meta |        see
#> size_text       |       plot.see_parameters_brms_meta |        see
#> size_bar        |    plot.see_parameters_distribution |        see
#> size_text       |             plot.see_parameters_efa |        see
#> size            |             plot.see_parameters_efa |        see
#> size_point      |           plot.see_parameters_model |        see
#> size_text       |           plot.see_parameters_model |        see
#> size_text       |             plot.see_parameters_pca |        see
#> size            |             plot.see_parameters_pca |        see
#> size_point      |             plot.see_parameters_sem |        see
#> size_line       |        plot.see_parameters_simulate |        see
#> size_line       |       plot.see_performance_pp_check |        see
#> size_point      |       plot.see_performance_pp_check |        see
#> size_bar        |       plot.see_performance_pp_check |        see
#> size_axis_title |       plot.see_performance_pp_check |        see
#> size_title      |       plot.see_performance_pp_check |        see
#> base_size       |       plot.see_performance_pp_check |        see
#> size_line       |         plot.see_performance_simres |        see
#> size_point      |         plot.see_performance_simres |        see
#> size_title      |         plot.see_performance_simres |        see
#> size_axis_title |         plot.see_performance_simres |        see
#> base_size       |         plot.see_performance_simres |        see
#> size_point      |             plot.see_point_estimate |        see
#> size_text       |             plot.see_point_estimate |        see
#> size_line       |      print.see_performance_pp_check |        see
#> size_point      |      print.see_performance_pp_check |        see
#> size_bar        |      print.see_performance_pp_check |        see
#> size_axis_title |      print.see_performance_pp_check |        see
#> size_title      |      print.see_performance_pp_check |        see
#> base_size       |      print.see_performance_pp_check |        see

@bwiernik
Copy link
Contributor

size_line we should change to linewidth since that's the correct ggplot2 argument now

@bwiernik
Copy link
Contributor

Let's leave font_size

@IndrajeetPatil IndrajeetPatil marked this pull request as ready for review November 21, 2024 20:55
@strengejacke
Copy link
Member

I think we should change the arguments in check_model(), too, to align with the plot-functions?
https://easystats.github.io/performance/reference/check_model.html

@bwiernik
Copy link
Contributor

Yep absolutely. Are there other functions that also have plotting arguments?

@strengejacke
Copy link
Member

I don't think so. It's because check_model does only plotting, you don't need to plot() explicitly. that's why you be pass those arguments directly in check_model. Maybe binned_residuals or check_predictions, I'll check

Copy link
Contributor

@bwiernik bwiernik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of places where we say "color" to refer fill type variables. Should we switch to "fill_" for those? I'm leaning toward no, as we use one color argument to set both fill and color aesthetics in several places

#' @param dispersion_alpha Numeric value specifying the transparency level of dispersion ribbon.
#' @param dispersion_color Character specifying the color of dispersion ribbon.
#' @param alpha_dispersion Numeric value specifying the transparency level of dispersion ribbon.
#' @param color_dispersion Character specifying the color of dispersion ribbon.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be fill_dispersion?

#' @param dispersion_style Character describing the style of dispersion area.
#' `"ribbon"` for a ribbon, `"curve"` for a normal-curve.
#' @param highlight A vector with names of categories in `x` that should be
#' highlighted.
#' @param highlight_color A vector of color values for highlighted categories.
#' @param color_highlight A vector of color values for highlighted categories.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be fill_highlight?

@@ -12,7 +12,7 @@
#' If `TRUE`, confidence intervals computed using the Wilson method are shown.
#' See Brown et al. (2001) for details.
#' @param ci Confidence Interval (CI) level. Defaults to `0.95` (`95%`).
#' @param fill_col Color to use for category columns (default: `"#87CEFA"`).
#' @param color_fill Color to use for category columns (default: `"#87CEFA"`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be fill_bar or just fill?

@strengejacke
Copy link
Member

There are a couple of places where we say "color" to refer fill type variables. Should we switch to "fill_" for those? I'm leaning toward no, as we use one color argument to set both fill and color aesthetics in several places

I think we don't need to fully adopt the ggplot2 aes names. If it's a color aesthetic, no matter if for points, lines, or ribbons, color_* is ok.

@strengejacke
Copy link
Member

size_line we should change to linewidth since that's the correct ggplot2 argument now

I'm fine with both, we could also keep size_* for anything that changes geom sizes in a certain way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants