This vignette introduces nice and easy way to display grouped data
frame created by dplyr::group_by
.
grouped_iris <- iris %>%
group_by(Species) %>%
slice(1, 2)
grouped_mtcars <- mtcars %>%
mutate(model = rownames(mtcars)) %>%
head() %>%
select(model, cyl, mpg, disp, am) %>%
group_by(am, cyl)
By specifying as_flextable(groups_to = 'merged')
,
grouping variables are merged vertically. In this case, the default
theme is changed to flextable::theme_vanilla
because the
booktab theme is not intuitive.
grouped_mtcars %>%
as_flextable(groups_to = "merged", groups_arrange = TRUE)
#> Warning: ftExtra:::as_flextable.data.frame is deprecated and will be removed in
#> the future release. Consider using flextalbe's implementation by running
#> `.S3method("as_flextable", "data.frame", flextable:::as_flextable.data.frame)`
grouped_mtcars %>%
as_flextable(groups_to = "merged", groups_arrange = FALSE)
#> Warning: ftExtra:::as_flextable.data.frame is deprecated and will be removed in
#> the future release. Consider using flextalbe's implementation by running
#> `.S3method("as_flextable", "data.frame", flextable:::as_flextable.data.frame)`
Grouping variables are moved to left by default. If you want to keep
their positions, specify group_pos = 'asis'
.
grouped_mtcars %>%
as_flextable(groups_to = "merged", groups_pos = "asis") %>%
flextable::theme_vanilla()
#> Warning: ftExtra:::as_flextable.data.frame is deprecated and will be removed in
#> the future release. Consider using flextalbe's implementation by running
#> `.S3method("as_flextable", "data.frame", flextable:::as_flextable.data.frame)`