kableextra

R Using kableExtra to colorize cells and maintain striped formatting with nested if/ifelse?

雨燕双飞 提交于 2020-01-06 08:08:23
问题 An expansion to this question: R wanting to limit the amount of digits from csv file I am using kableExtra and cell_spec to colorize cells with nested ifelse statements. Instead of colorizing values less than .10 white, I want to leave them alone in order to allow kableExtra to apply the striped formatting. I have a feeling this isn't possible though because of how the background colors are applied? DF: DF <- data.frame(V1 = sample(letters,10,T), V2 = abs(rnorm(10)), V3 = abs(rnorm(10))) Code

Efficient way to wrap column names of proportion tables in rmarkdown pdf output

白昼怎懂夜的黑 提交于 2020-01-03 19:33:07
问题 I'm making weighted tables of row proportions using the questionr package. I want to wrap the column names when they are too long. Because I'm making hundreds of tables, the solution needs to work on tables with varying numbers of columns. I also want to avoid setting all columns to a specific width. Ideally, short column names would remain at their normal width while names exceeding the specified maximum length would be wrapped. Here are a bunch of solutions I've tried so far, written as

Make html table columns wider / prevent words from wrapping in RMarkdown

拥有回忆 提交于 2020-01-03 01:22:47
问题 I'm creating an html document with R markdown which has some tables. In situations where one column of a table has character values, how can I ensure the column is wide enough to contain the entire character string without wrapping? I tried using kableExtra below, but it seems like the width argument of column_spec is not being used even though the bold argument is. library(data.table) csd <- fread(' Oct-17 Sep-17 Aug-17 Jul-17 Jun-17 May-17 Apr-17 Mar-17 Feb-17 Jan-17 Dec-16 Nov-16 Oct-16

R markdown: How to create a table with images and text which should be knitted as PDF?

只愿长相守 提交于 2019-12-29 01:53:10
问题 I would like to include a table with 2 columns including images and text (image descriptions) in PDF report compiled with R markdown. In doing so, I have the following requirements for my table: width: fixed column or table width alignment: content alignment in columns top center alignment of an image in column 1 top left alignment of text in column 2 text content: is at best easy and good to read also in code text formatting: text formatting required, at best using markdown syntax, i.e, bold

Conditionally formatting cells in one column by comparing it with the value from another column using Kable

偶尔善良 提交于 2019-12-25 01:46:09
问题 I am new to R and we know in Excel it is very easy to conditionally format a cell (change the background colour) by comparing with another column. I tried to do this in R using KableExtra. But I could not succeed in fetching value from another row and comparing it. My task was making a cell to appear green, yellow or red by comparing a cell on another column in the same row. library(kableExtra) library(dplyr) library(knitr) multirow_spec <- function(x, rows, ...) { for (row in rows) x <-

How to group columns in R markdown?

与世无争的帅哥 提交于 2019-12-24 08:47:19
问题 I am trying to generate a table using kable and saving the output as a markdown. I am later using pandoc to convert markdown to pdf. For my table I would like to group my table columns into two groups. It seems that this could be achieved using the kableExtra "add_header_above" function, but unfortunately the output cannot be stored as markdown. Is there a way to group columns using markdown? I am pasting my dummy code below. Appreciate all comments and suggestions. library(knitr) library

Map cell colors to data values in kableExtra to create a heatmap table

安稳与你 提交于 2019-12-24 00:46:52
问题 I have a table below and would like to apply ROW-level heat maps. (1) Any idea how? Right now the heat map is the same for both values in the single row below. (2) Is there a way to make the header for the group column NOT be angled 90 degrees? Right now all headers are angled but for the group column it be better without angle=90. here is the rmd file. --- title: "Untitled" output: pdf_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(dplyr) library

Rmarkdown : can we merge two cells with kableExtra?

好久不见. 提交于 2019-12-24 00:36:35
问题 Is there a way to merge two cells with kableExtra when knitting from Rmarkdown to HTML? bbb = 5 aaa = data.frame(matrix(c(1,2,3,4, paste(bbb),""), nrow = 2, byrow = T)) aaa I want the value bbb (the value of the merged cells varies) to appear in the middle of the last two columns when applying kable(aaa) %>% kableExtra(...) > aaa X1 X2 X3 1 1 2 3 2 4 5 Any suggestion ? Thanks :-) 来源: https://stackoverflow.com/questions/58132626/rmarkdown-can-we-merge-two-cells-with-kableextra

kableExtra only works if there's another table in the presentation?

做~自己de王妃 提交于 2019-12-21 17:54:52
问题 When I use kableExtra for a PDF output, the table renders beautifully, BUT gives an error if there isn't another, non-kable extra table in the program. Has anyone else seen this behavior? the file appears to knit fine, but then throws an error in pandoc? For example, this code: --- output: beamer_presentation: fontsize: 10pt --- ```{r global_options, include=FALSE} library(rmarkdown) library(knitr) library(kableExtra) ``` ### Slide with table ```{r echo=FALSE, warning=FALSE, message=FALSE} df

KableExtra conditionally formatting specific rows on a column

独自空忆成欢 提交于 2019-12-21 06:45:26
问题 I have just learnt KableExtra and know to how to use conditionally formating the entire column using mutate() as explained in the doc using mutate such as: mutate( mpg = cell_spec(mpg, background = ifelse(mpg > 20, "red", "blue")) ) But what I don't know is, how to change background colours of only certain rows in each column whilst all rows are being displayed. For example, my data: df <- data.frame( region1 = c("A", sample(1:5,3)), region2 = c("B", sample(1:5,3)), region3 = c("C", sample(1