JK Lambert
JK Lambert

Reputation: 353

Justify Second Column to the right

I was wondering if anyone knows how to align a ggtexttable column to the right?

This is a brief example:

library(ggpubr)

df <- data.frame(Order = c(1:3),
                 Name = c("Adam", "Ben", "Charlie"), 
                 Score = c(-.0041, 8.00, 9.123))
stable.p <- ggtexttable(df, rows = NULL, theme = ttheme("default"))

ggarrange(stable.p,  ncol = 1, nrow = 1, heights = c(1, 1))

The second column with the negative sign and the decimals just looks bad, I would like to justify that second column to the right, thanks in advance.

Upvotes: 0

Views: 393

Answers (1)

Daniel_j_iii
Daniel_j_iii

Reputation: 3252

Utilizing the package documentation The best I could do was force all columns to the right. It may also depend on your YAML settings. What output are you rendering to? I may have had different results since I am using html_document

BEFORE: enter image description here

AFTER:enter image description here

with the package you specify your table body style, and then map it inside your ggtexttable() function.

tbody.style = tbody_style(hjust=1, x=0.9)

This is my reproducible solution

---
title: "Untitled"
author: "author"
date: "6/11/2021"
output: html_document
---

```{r setup}
library(ggpubr)

tbody.style = tbody_style(hjust=1, x=0.9)

df <- data.frame(Order = c(1:3),
                 Name = c("Adam", "Ben", "Charlie"), 
                 Score = c(-.0041, 8.00, 9.123))


ggtexttable(df, rows = NULL, 
            theme = ttheme(tbody.style = tbody.style))


```

Upvotes: 0

Related Questions