How can I order the output columns of a qwraps2 summary_table in R? When running the code underneath the first column of the table presents the output for 6 cylinders, then 4 cylinders, then 8 cylinders.

I tried ordering the data but this has no effect on the output table.

library(qwraps2)
mtcars2 <-
  dplyr::mutate(mtcars,
                cyl_factor = factor(cyl,
                                    levels = c(6, 4, 8),
                                    labels = paste(c(6, 4, 8), "cylinders")),
                cyl_character = paste(cyl, "cylinders"))


our_summary1 <-
  list("Miles Per Gallon" =
         list("min" = ~ min(.data$mpg),
              "max" = ~ max(.data$mpg),
              "mean (sd)" = ~ qwraps2::mean_sd(.data$mpg)),
       "Displacement" =
         list("min" = ~ min(.data$disp),
              "median" = ~ median(.data$disp),
              "max" = ~ max(.data$disp),
              "mean (sd)" = ~ qwraps2::mean_sd(.data$disp)),
       "Weight (1000 lbs)" =
         list("min" = ~ min(.data$wt),
              "max" = ~ max(.data$wt),
              "mean (sd)" = ~ qwraps2::mean_sd(.data$wt)),
       "Forward Gears" =
         list("Three" = ~ qwraps2::n_perc0(.data$gear == 3),
              "Four"  = ~ qwraps2::n_perc0(.data$gear == 4),
              "Five"  = ~ qwraps2::n_perc0(.data$gear == 5))
  )

by_cyl <- summary_table(dplyr::group_by(mtcars2, cyl_factor), our_summary1)
by_cyl

I would like to visualize this in an increasing order (first 4 then 6 then 8).

0 Answers

Related Questions