kable

kableExtra how to use cell_spec from a user defined range?

这一生的挚爱 提交于 2021-02-17 03:28:27
问题 First, the package kableExtra indeed produces awesome table. I just have an additional request : When running this example ( from the manual) iris[1:10, ] %>% select(-Species) %>% mutate_if(is.numeric, function(x) { cell_spec(x, "latex", bold = T, color = spec_color(x, end = 0.9), font_size = spec_font_size(x)) }) %>% kable("latex", escape = F, booktabs = T, linesep = "", align = "c") The cells are formated in each column. (1) How to adjust them to the entire table ? (2) Or to a user defined

kable, collapse_rows and booktabs: no alignement to the top

匆匆过客 提交于 2021-02-11 17:01:26
问题 I am trying to print a data.frame in a pdf using kable and collapse_rows functions. And it did not manage to make it works. Please try the following reprex: --- title: "Example" output: bookdown::pdf_document2 --- ```{r bandIdentif, echo=F} library(dplyr);library(kableExtra) dt <- data.frame(A = c(rep("a", 2), rep("b", 3)), B = c(paste("answer", 1:5))) kable(dt, "latex") %>% collapse_rows(columns = 1, valign = "top") ``` I have updated all the packages (MaxTex and R) and Rstudio. However, the

How do I get kable and formattable to work together when creating a table in R?

折月煮酒 提交于 2021-02-11 14:32:26
问题 Both kableExtra and formattable have fantastic features and I'll like to be able to incorporate them both in my tables. Here is the table formatted using formattable: Health_status = c("Very good", "Good", "Fair", "Bad", "Very bad", "Not stated", "Total") Number = c(1032169, 453975, 125502, 22095, 5019, 73528, 1712288) Percent = c(60.3, 26.5, 7.3, 1.3, 0.3, 4.3, 100) Change = c(37672, 15231, 6536, 1988, 525, 30315, 92267) Percent_Change = c(3.8, 3.5, 5.5, 9.9, 11.7, 70.2, 5.7) df <- data

Change background colour of knitr::kable headers

北战南征 提交于 2021-02-08 06:13:35
问题 I need to change the background colour of the headers of a table printed with knitr::kable. I can use kableExtra::column_spec to change the background of a whole column, but it doesn't affect the header row: library(knitr) library(kableExtra) kable(data.frame(a = 1, b = 2)) %>% column_spec(1, background = "yellow") Wanted outcome: A kable output where the header of column a has a yellow background (and the rest of the table a white background). 回答1: You can do this using cell_spec . For

How to align table and plot in rmarkdown html_document

青春壹個敷衍的年華 提交于 2021-02-08 05:01:54
问题 How can I align a kable table to be adjacent to a ggplot2 plot in an rmarkdown html_document? Foo.Rmd --- title: "Foo" output: html_document --- ```{r setup, include=FALSE} library(ggplot2) library(knitr) library(kableExtra) ``` # Table next to plot ```{r echo = FALSE} kable(head(iris)) %>% kable_styling(bootstrap_options = "striped", full_width = F) ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point() ``` I tried following the solution here but to no avail. 回答1: A great

Latex symbols in rmarkdown table using knitr::kable

拥有回忆 提交于 2021-02-07 20:59:37
问题 I am trying to use knitr::kable in Rmarkdown to create a table of latex equations. However, I am having difficulties getting special characters such as $\sum$ or $\hat$ to work. For example the following works: knitr::kable(head(mtcars[,c(1,2)], 10), row.names = FALSE, col.names = c("Time", "$\\delta_{m}_1$")) but when trying to include a hat or bar the following does not work: knitr::kable(head(mtcars[,c(1,2)], 10), row.names = FALSE, col.names = c("Time", "$\\hat{m}_1$")) Has anyone figured

kableExtra HTML styling in Rmarkdown and kable_save()

眉间皱痕 提交于 2021-01-29 22:20:41
问题 This has plagued me for too long, I would appreciate help. I have been investing time into kable, but it hasn't quite worked out for me the way I would like. I am looking to create multi grouped rows as in the image The code to do this is as follows: collapse_rows_dt <- expand.grid( District = sprintf('District %s', c('1', '2')), City = sprintf('City %s', c('1', '2')), State = sprintf('State %s', c('a', 'b')), Country = sprintf('Country with a long name %s', c('A', 'B')) ) collapse_rows_dt <-

kableExtra HTML styling in Rmarkdown and kable_save()

99封情书 提交于 2021-01-29 21:49:10
问题 This has plagued me for too long, I would appreciate help. I have been investing time into kable, but it hasn't quite worked out for me the way I would like. I am looking to create multi grouped rows as in the image The code to do this is as follows: collapse_rows_dt <- expand.grid( District = sprintf('District %s', c('1', '2')), City = sprintf('City %s', c('1', '2')), State = sprintf('State %s', c('a', 'b')), Country = sprintf('Country with a long name %s', c('A', 'B')) ) collapse_rows_dt <-

Using a for loop with knitr::kable and kableExtra::add_header_above

…衆ロ難τιáo~ 提交于 2021-01-29 14:18:38
问题 I am using R version 3.5.2 . I would like to evaluate a string in a kable function , but I am having some issues. Normally, I can pass a string through a for loop using the get function but in the kableExtra::add_header_above function I get the following error: Error: unexpected '=' in:"print(kable(df4,"html", col.names = c("zero","one")) %>% add_header_above(c(get("string") =" I have tried a handful of techniques like creating a string outside of the kable function and calling it, using page

html kable_styling not showing output in a for loop

℡╲_俬逩灬. 提交于 2021-01-29 08:15:07
问题 I want to use kable inside a for loop to generate a lot of tables in a HTML rmarkdown. I was looking for solutions and most of them are solved using the wrapper print around kable code. But when I want to generate html table outputs with kable_styling, this solution didn't work! For example: table <- tibble(a = c(1:10), b = letters[1:10]) for(each in 1:2) { print(table %>% kable()) cat("<br>") } This generate two simple tables. But when I try: table <- tibble(a = c(1:10), b = letters[1:10])