easystats / see

:art: Visualisation toolbox for beautiful and publication-ready figures
https://easystats.github.io/see/
Other
879 stars 43 forks source link

Plot method for `data_tabulate` #293

Closed etiennebacher closed 1 year ago

etiennebacher commented 1 year ago

Close #289

Minimal working version so far (no docs, etc.). It is such a short step to convert the table into a plot that I think we should restrict the number of args to a minimum here. Otherwise it will just be quicker for the users to make a fancy plot by themselves than go through all possible args (e.g the docs of sjPlot::plot_freq() are a bit overwhelming 😅). I have two "important" args in mind for now:

@jmgirard what do you think?

library(see)
library(datawizard)
library(patchwork)

x <- data_tabulate(mtcars, select = "cyl")
plot(x)
#> [[1]]


x <- data_tabulate(mtcars, select = c("cyl", "gear"))
my_plots <- plot(x)
wrap_plots(my_plots)

bwiernik commented 1 year ago

A few comments:

  1. we should include error bars by default
  2. I think we should apply theme_modern() as the default theme for all plots in see
  3. We should relabel "NA" to "(Missing)" and have an argument for the label to use in addition to whether or not to inlcude.
etiennebacher commented 1 year ago
library(see)
library(datawizard)
library(patchwork)

x <- data_tabulate(mtcars, select = "cyl")
plot(x)
#> [[1]]


plot(x, remove_na = TRUE)
#> [[1]]


plot(x, na_label = "Missing values")
#> [[1]]

bwiernik commented 1 year ago

Looking good! Error bars?

etiennebacher commented 1 year ago

@bwiernik did you have something like this in mind? Default is to add error bars (I just took the code from sjPlot::plot_frq())

library(see)
library(datawizard)
library(patchwork)

x <- data_tabulate(mtcars, select = "cyl")

plot(x, remove_na = TRUE)
#> [[1]]


plot(x, remove_na = TRUE, error_bar = FALSE)
#> [[1]]

Created on 2023-06-02 with reprex v2.0.2

etiennebacher commented 1 year ago

Remaining tests failures are not caused by this PR, they are also on main

strengejacke commented 1 year ago

I think this can be merged?

bwiernik commented 1 year ago

I'm making some tweaks

bwiernik commented 1 year ago

okay, I made those tweaks. The major one is to use the Wilson CI for proportions rather than the normal approximation -- this avoids getting CI bounds that escape [0, 1] or intervals collapsing to nothing at p = 0 or 1

bwiernik commented 1 year ago

this is ready to merge assuming checks still pass

bwiernik commented 1 year ago

@IndrajeetPatil do you know why the R-CMD-check-strict on ubuntu is taking forever to load all of the dependencies?

strengejacke commented 1 year ago

The automated checks for the see package are a pain, because there are a lot of minor issues, which yield an error (on purpose), but which are difficult to iron out in order to have a "clean basis" for tests.

IndrajeetPatil commented 1 year ago

@IndrajeetPatil do you know why the R-CMD-check-strict on ubuntu is taking forever to load all of the dependencies?

Possibly due to this issue: https://github.com/r-lib/vdiffr/issues/137

bwiernik commented 1 year ago

That looks like it