xtable

Captions on tables in pdf documents generated by rmarkdown

a 夏天 提交于 2019-12-18 16:25:11
问题 How can I get captions on my table floats in pdf_document generated by rmarkdown? Using output: pdf_document: fig_caption: true and ```{r, fig.cap='a caption'} myplot ``` Generates a floating figure with myplot and the caption specified. How do I achieve the same thing with tables generated by xtable? ```{r, results='asis', fig.cap='table caption'} print(xtable(table), comment = FALSE) ``` I have tried using floating.environment = 'figure' in print.xtable, but to no avail. 回答1: Or similarly,

How to get dimnames in xtable.table output?

心不动则不痛 提交于 2019-12-18 15:34:42
问题 I'd like to have the dimensions labeled in my xtable output. However, the table method of xtable does not output dimension labels even when I specify them manually to table : set.seed(10) d <- data.frame(x=sample(1:4),y=sample(1:4)) tb <- with(d, table(d,dnn=c("Xs","Ys"))) > tb Ys Xs 1 2 3 4 1 0 0 0 1 2 0 1 0 0 3 1 0 0 0 4 0 0 1 0 > xtable(tb) % latex table generated in R 2.15.1 by xtable 1.7-0 package % Tue Oct 9 09:06:10 2012 \begin{table}[ht] \begin{center} \begin{tabular}{rrrrr} \hline &

Changing the Color of negative numbers to Red in a table generated with xtable()?

时间秒杀一切 提交于 2019-12-18 12:53:16
问题 I'm writing a report in R with knitr. I'm using xtable() to generate tables in the report. One of my tables includes both negative and positive numbers. I'd like to change the color of negative numbers into red. How can I do that? Obviously, one easy solution is to change the latex code that xtable generates BUT note that I have an auto-report that numbers can change with new datasets and I don't want to manually set the colors. Here is a simple code: \documentclass{article} \begin{document}

How to center LaTeX xtable output in full text width

自闭症网瘾萝莉.ら 提交于 2019-12-18 07:35:23
问题 I am using tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) to create a small report in latex. I have a file code.Rnw that I knit into code.tex. Below is my code.Rnw: \documentclass[12pt,english,nohyper]{tufte-handout} \usepackage{longtable} \usepackage{geometry} \begin{document} <<include=FALSE>>= library(ggplot2) library(xtable) @ \centerline{\Large\bf This is my Main Title} <<echo=FALSE,results='asis'>>= fname='plot1.pdf' pdf(fname,width=4

knitr, R Markdown, and xtable: xtable tables within HTML table

夙愿已清 提交于 2019-12-18 03:39:51
问题 Suppose I want to print HTML tables using xtable, side-by-side. I tried doing this in an .Rmd file with: <table border = 1> <tr> <td> `r functionThatPrintsAnHTMLTableUsingxtable` </td> <td> `r functionThatPrintsAnotherHTMLTableUsingxtable` </td> </tr> </table> No dice. What am I doing wrong? Thanks. 回答1: I think your code will work if you put results=asis in the chunk options. <table border = 1> <tr> <td> ```{r results='asis', echo=FALSE} library(xtable) data(tli) print(xtable(tli[1:20, ])

how to flip a regression table in stargazer?

我们两清 提交于 2019-12-14 01:15:43
问题 I would like to "flip" the row/columns in a regression table. The latest stargazer manuals says that now the flip argument also works with regression tables (previously it only worked with summary stats). However I am unable to make it work. Here is an example with stargazer 5.2.1 library(stargazer) stargazer(attitude) linear.1 <- lm(rating ~ complaints + privileges + learning + raises + critical, data=attitude) linear.2 <- lm(rating ~ complaints + privileges + learning, data=attitude) ##

plot xtable or save it as image

旧街凉风 提交于 2019-12-13 07:49:15
问题 I want to use xtable layouts in my powerpoint presentations and I need a way to directly convert a data.frame into a picture or plot of an xtable such as the ones displayed here. The ideal solution would give me a ggplot object as I have the most flexibility from there, but I can work with another output as long as I can see a xtable in a pic (raster or vector) or plot window. 回答1: Using ggplot2 and grid.extra we can achieve decently looking tables: library(ggplot2) library(gridExtra) ggplot(

xtable output for a list of tables

[亡魂溺海] 提交于 2019-12-12 18:55:11
问题 I've a list of tables and want to sweave it for LaTex output. Here is the code: Data <- esoph[ , 1:3] library(plyr) combos <- combn(ncol(Data),2) TabelFn <- function(x) { Table <- addmargins(table(Data[, x[1]], Data[, x[2]])) return(Table) } Table <- alply(.data=combos, .margins=2, .fun=TabelFn, .expand=TRUE) library(xtable) The list Table has three contingency tables in this case and I can sweave the output to LaTex using this code: << label = tabTable, echo = FALSE, results = tex >>= print

Include label attribute into xtable header

别来无恙 提交于 2019-12-12 18:19:37
问题 Reproducible example: I have a data frame which has labelled variables using the sjmisc package, which works nicely together with dplyr since v0.4.2. library(dplyr) library(sjmisc) library(ggplot2) data("diamonds") df= tbl_df(diamonds) %>% select(cut, carat, price) %>% set_label(c("", "Kt", "EUR")) %>% slice(1:10) As str(df) shows it properly contains for two columns the labels: Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 10 obs. of 3 variables: $ cut : Ord.factor w/ 5 levels "Fair"<"Good"<..:

xtable left just

泄露秘密 提交于 2019-12-12 11:25:00
问题 the default of xtable is \begin{center} . I would like to make it: \begin{left} and \end{left} as well. Code: library(xtable) xtable(anova(lm(mpg~hp, data=mtcars))) Desired outcome: \begin{table}[ht] \begin{left} \begin{tabular}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\ \hline hp & 1 & 678.37 & 678.37 & 45.46 & 0.0000 \\ Residuals & 30 & 447.67 & 14.92 & & \\ \hline \end{tabular} \end{left} \end{table} 回答1: print(xtable(anova(lm(mpg~hp, data=mtcars))) , booktabs=TRUE,