library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.3 ✓ purrr 0.3.4
## ✓ tibble 3.1.0 ✓ dplyr 1.0.5
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
glimpse(iris)
## Rows: 150
## Columns: 5
## $ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.…
## $ Sepal.Width <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.…
## $ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1.…
## $ Petal.Width <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.…
## $ Species <fct> setosa, setosa, setosa, setosa, setosa, setosa, setosa, s…
iris <- iris[,c(5,1:4)]
glimpse(iris)
## Rows: 150
## Columns: 5
## $ Species <fct> setosa, setosa, setosa, setosa, setosa, setosa, setosa, s…
## $ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.…
## $ Sepal.Width <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.…
## $ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1.…
## $ Petal.Width <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.…
## Using kable
library(knitr)
iris %>%
head %>%
kable()
Species | Sepal.Length | Sepal.Width | Petal.Length | Petal.Width |
---|---|---|---|---|
setosa | 5.1 | 3.5 | 1.4 | 0.2 |
setosa | 4.9 | 3.0 | 1.4 | 0.2 |
setosa | 4.7 | 3.2 | 1.3 | 0.2 |
setosa | 4.6 | 3.1 | 1.5 | 0.2 |
setosa | 5.0 | 3.6 | 1.4 | 0.2 |
setosa | 5.4 | 3.9 | 1.7 | 0.4 |
## Using kableExtra
library(kableExtra)
##
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
##
## group_rows
iris %>% head %>%
kable(caption = "Table 1. Annotate with kableExtra") %>%
kable_styling(c("striped", "hover", "condensed"), full_width = F,
position = "left") %>%
add_header_above(c("categorical"=1, "numerical" = 4)) %>%
column_spec(1, bold = T) %>%
row_spec(0, italic = T)
Species | Sepal.Length | Sepal.Width | Petal.Length | Petal.Width |
---|---|---|---|---|
setosa | 5.1 | 3.5 | 1.4 | 0.2 |
setosa | 4.9 | 3.0 | 1.4 | 0.2 |
setosa | 4.7 | 3.2 | 1.3 | 0.2 |
setosa | 4.6 | 3.1 | 1.5 | 0.2 |
setosa | 5.0 | 3.6 | 1.4 | 0.2 |
setosa | 5.4 | 3.9 | 1.7 | 0.4 |
library(rmarkdown)
paged_table(iris)
iris %>%
DT::datatable()
iris %>%
DT::datatable(extensions = c('Buttons', 'FixedColumns', 'RowReorder'),
filter = 'top',
caption = 'Iris table using DT datatable',
options = list(
autoWidth = TRUE,
pageLength = 10, # dom = 'Bfrtip',
buttons=list(list(extend = 'colvis', columns = c(3:5))),
# fixedColumns = list(leftColumns = 2), #, rightColumns = 1),
rowReorder = TRUE, order = list(c(0, 'asc')),
scrollX = TRUE,
lengthMenu = c(10, 25, 100)
))