larmarange / ggstats

Extension to ggplot2 for plotting stats
https://larmarange.github.io/ggstats/
GNU General Public License v3.0
26 stars 1 forks source link

Package must be loaded to namespace for gglikert() and cousins to work #47

Closed sda030 closed 10 months ago

sda030 commented 10 months ago

Tried the examples for the gglikert() help page, by only adding the ggstats::-prefix, but then a weird error arises. Not having to load entire packages into namespaces is rather useful for package development and Quarto use (where memory management is an issue).

library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

likert_levels <- c(
    "Strongly disagree",
    "Disagree",
    "Neither agree nor disagree",
    "Agree",
    "Strongly agree"
)
set.seed(42)
df <-
    tibble(
        q1 = sample(likert_levels, 150, replace = TRUE),
        q2 = sample(likert_levels, 150, replace = TRUE, prob = 5:1),
        q3 = sample(likert_levels, 150, replace = TRUE, prob = 1:5),
        q4 = sample(likert_levels, 150, replace = TRUE, prob = 1:5),
        q5 = sample(c(likert_levels, NA), 150, replace = TRUE),
        q6 = sample(likert_levels, 150, replace = TRUE, prob = c(1, 0, 1, 1, 0))
    ) %>%
    mutate(across(everything(), ~ factor(.x, levels = likert_levels)))

ggstats::gglikert(df)
#> Error in `geom_bar()`:
#> ! Can't find stat called "prop"
#> Backtrace:
#>     ▆
#>  1. └─ggstats::gglikert(df)
#>  2.   └─ggplot2::geom_bar(...)
#>  3.     └─ggplot2::layer(...)
#>  4.       └─ggplot2:::check_subclass(...)
#>  5.         └─cli::cli_abort("Can't find {argname} called {.val {x}}", call = call)
#>  6.           └─rlang::abort(...)

Created on 2023-09-27 with reprex v2.0.2

larmarange commented 10 months ago

it should be fixed by #48

could you try?

sda030 commented 10 months ago

Yes, works now! Thanks!