h u x
table

 

Introduction Design Github Bugs

Huxtable is an R package for creating HTML and LaTeX tables. It provides similar functionality to xtable, but more, with a simpler interface. Here are some quick examples:

ht <- hux(
        Employee = c('John Smith', 'Jane Doe', 'David Hugh-Jones'),
        Salary = c(50000, 50000, 40000),
        add_colnames = TRUE
      )

bold(ht)[1,]           <- TRUE
bottom_border(ht)[1,]  <- 1
align(ht)[,2]          <- 'right'
right_padding(ht)      <- 10
left_padding(ht)       <- 10
width(ht)              <- 0.35

ht
Employee Salary
John Smith 50000.00
Jane Doe 50000.00
David Hugh-Jones 40000.00
library(magrittr)
ht <- hux(
        Employee = c('John Smith', 'Jane Doe', 'David Hugh-Jones'),
        Salary = c(50000, 50000, 40000),
        add_colnames = TRUE
      )

ht                                        %>%
      set_bold(1, everywhere, TRUE)       %>%
      set_bottom_border(1, everywhere, 1) %>%
      set_align(everywhere, 2, 'right')   %>%
      set_right_padding(10)               %>%
      set_left_padding(10)                %>%
      set_width(0.35)
Employee Salary
John Smith 50000.00
Jane Doe 50000.00
David Hugh-Jones 40000.00
library(psych)
data(attitude)
att_corr <- corr.test(as.matrix(attitude))

as_hux(att_corr$r)                                                             %>%
      set_background_color(where(att_corr$p < 0.05), 'yellow')                 %>%
      set_background_color(where(att_corr$p < 0.01), 'orange')                 %>%
      set_background_color(where(row(att_corr$p) == col(att_corr$p)), 'white') %>%
      huxtable::add_rownames(colname = '')                                     %>%
      huxtable::add_colnames()                                                 %>%
      set_all_borders(1)
rating complaints privileges learning raises critical advance
rating 1.00 0.83 0.43 0.62 0.59 0.16 0.16
complaints 0.83 1.00 0.56 0.60 0.67 0.19 0.22
privileges 0.43 0.56 1.00 0.49 0.45 0.15 0.34
learning 0.62 0.60 0.49 1.00 0.64 0.12 0.53
raises 0.59 0.67 0.45 0.64 1.00 0.38 0.57
critical 0.16 0.19 0.15 0.12 0.38 1.00 0.28
advance 0.16 0.22 0.34 0.53 0.57 0.28 1.00
data(diamonds, package = 'ggplot2')

lm1 <- lm(price ~ carat, diamonds)
lm2 <- lm(price ~ depth, diamonds)
lm3 <- lm(price ~ carat + depth, diamonds)

huxreg(lm1, lm2, lm3)
(1) (2) (3)
(Intercept) -2256.361 *** 5763.668 *** 4045.333 ***
(13.055)    (740.556)    (286.205)   
carat 7756.426 ***          7765.141 ***
(14.067)             (14.009)   
depth          -29.650 *   -102.165 ***
         (11.990)    (4.635)   
N 53940         53940         53940        
R2 0.849     0.000     0.851    
logLik -472730.266     -523772.431     -472488.441    
AIC 945466.532     1047550.862     944984.882    
*** p < 0.001; ** p < 0.01; * p < 0.05.

To learn more, check out the vignette in HTML or PDF format, or the original R Markdown. Or, read the design principles behind huxtable, including a comparison with other R packages to create tables.

Installation

From CRAN:

install.packages('huxtable')

Development version from github:

library(devtools)
install_github('hughjonesd/huxtable')

The name

Huxtable could stand for "Happy User Xtable", or if you prefer, "Hyped Up Xtable", or for Germans maybe "Html Und teX Table".

Trivia

The logo above was also generated by a huxtable, using hux_logo(). The web page background is a statistical table from Mayhew's London Labour and the London Poor, a classic of Victorian social science.