On those occasions where you need to move columns this way or that way, we
can make use of the
cols_move() function. While it's true that the movement
of columns can be done upstream of gt, it is much easier and less error
prone to use the function provided here. The movement procedure here takes
one or more specified columns (in the
columns argument) and places them to
the right of a different column (the
after argument). The ordering of the
columns to be moved is preserved, as is the ordering of all other columns
in the table.
A table object that is created using the
The column names to move to as a group to a different position. The order of the remaining columns will be preserved.
A column name used to anchor the insertion of the moved columns. All of the moved columns will be placed to the right of this column.
The columns supplied in
columns must all exist in the table and none of
them can be in the
after argument. The
after column must also exist and
only one column should be provided here. If you need to place one or columns
at the beginning of the column series, the
should be used. Similarly, if those columns to move should be placed at the
end of the column series then use
An object of class
1 2 3 4 5 6 7 8 9 10 11 12 13
# Use `countrypops` to create a gt table; # With the remaining columns, position # `population` after `country_name` tab_1 <- countrypops %>% dplyr::select(-contains("code")) %>% dplyr::filter(country_name == "Mongolia") %>% tail(5) %>% gt() %>% cols_move( columns = vars(population), after = vars(country_name) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.