Home > Blockchain >  How to rotate the column headers with R package gt?
How to rotate the column headers with R package gt?

Time:04-05

Is there a way to rotate by 90 degrees the column headers with the gt package and make them vertical?

Thanks in advance!

CodePudding user response:

As Andrew has noted, there's not yet a built-in way of doing this but you can use custom CSS to style the table, although you may need to do some additional fine tuning of the elements to get it to look ok.

library(gt)

head(mtcars) %>%
  gt(id = "mygt") %>%
  tab_options(column_labels.padding = px(15),
              column_labels.padding.horizontal = px(7)) %>%
  cols_align("center", everything()) %>%
  opt_css(
  css = "
    #mygt .gt_col_heading {
      text-align: center;
      transform: rotate(-90deg);
      font-weight: bold;
    }
    "
)

enter image description here

CodePudding user response:

It looks like this might not be a feature yet in gt, as it is still in the enter image description here

Or using gridExtra (code from enter image description here

  • Related