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

Sorting in `gglikert` could be more flexible #55

Closed sda030 closed 4 months ago

sda030 commented 4 months ago

Hi! I was hoping I could sort in the case of a single question split on a multicategory y variable, but this is ignored. Is there a workaround not involving faceting? Same applies to gglikert_stacked.

library(ggstats)
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"
)
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),
        indep = sample(letters[1:5], 150, replace = TRUE)
    ) %>%
    mutate(across(-indep, ~ factor(.x, levels = likert_levels)))
gglikert(df, 
         include=q1,
         y=indep, 
         sort = "ascending")

Created on 2024-03-20 with reprex v2.1.0

larmarange commented 4 months ago

It should be possible to add an option to select the column to sort. Let me explore it next week

sda030 commented 4 months ago

Seems to work well, thanks mate!