IndrajeetPatil / ggstatsplot

Enhancing {ggplot2} plots with statistical analysis 📊📣
https://indrajeetpatil.github.io/ggstatsplot/
GNU General Public License v3.0
2.04k stars 190 forks source link

incorrect legend labels in `ggpiestats`? #458

Closed IndrajeetPatil closed 3 years ago

IndrajeetPatil commented 4 years ago
    library(ggstatsplot)

    # creating dataframe
    label <- c("a", "b", "c", "d")
    counts <- c(49, 30, 63, 59)
    (df <- data.frame(label, counts))
    #>   label counts
    #> 1     a     49
    #> 2     b     30
    #> 3     c     63
    #> 4     d     59

    # plot
    ggpiestats(df, label, counts = counts, results.subtitle = FALSE)

Created on 2020-09-27 by the reprex package (v0.3.0.9001)

IndrajeetPatil commented 4 years ago
> ggstatsplot:::cat_label_df(data = ggstatsplot:::cat_counter(data = df, x = label))
# A tibble: 4 x 3
  label counts  perc
  <chr>  <int> <dbl>
1 29.4%     59  29.4
2 31.3%     63  31.3
3 14.9%     30  14.9
4 24.4%     49  24.4
IndrajeetPatil commented 4 years ago
df <- dplyr::filter(mtcars, am == "0")
ggstatsplot::ggpiestats(df, am, cyl)
#> Registered S3 method overwritten by 'broom.mixed':
#>   method      from 
#>   tidy.gamlss broom
#> Registered S3 methods overwritten by 'lme4':
#>   method                          from
#>   cooks.distance.influence.merMod car 
#>   influence.merMod                car 
#>   dfbeta.influence.merMod         car 
#>   dfbetas.influence.merMod        car
#> Warning in broom.mixed::tidy(x, ...): restarting interrupted promise evaluation

#> Warning in broom.mixed::tidy(x, ...): restarting interrupted promise evaluation

#> Warning in broom.mixed::tidy(x, ...): restarting interrupted promise evaluation

Created on 2020-10-12 by the reprex package (v0.3.0.9001)

IndrajeetPatil commented 4 years ago
df <- dplyr::filter(mtcars, am == "0")
ggstatsplot::ggpiestats(df, am, cyl)
#> Registered S3 method overwritten by 'broom.mixed':
#>   method      from 
#>   tidy.gamlss broom
#> Registered S3 methods overwritten by 'lme4':
#>   method                          from
#>   cooks.distance.influence.merMod car 
#>   influence.merMod                car 
#>   dfbeta.influence.merMod         car 
#>   dfbetas.influence.merMod        car
#> Warning in broom.mixed::tidy(x, ...): restarting interrupted promise evaluation

#> Warning in broom.mixed::tidy(x, ...): restarting interrupted promise evaluation

#> Warning in broom.mixed::tidy(x, ...): restarting interrupted promise evaluation

Created on 2020-11-04 by the reprex package (v0.3.0)

IndrajeetPatil commented 3 years ago

One solution: rename the internal column from label to .label to avoid a possible clash with user-defined column.

IndrajeetPatil commented 3 years ago

Resolved!

df <- dplyr::filter(mtcars, am == "0")
ggstatsplot::ggpiestats(df, am, cyl)

Created on 2020-11-25 by the reprex package (v0.3.0.9001)