Reputation: 13
The output of the following code chunk is being devided into 2 blocks (figures 1 and 2) in the rendered pdf document, a first block containing the two first columns (Estimate and Std. Error) and another one for the remaining ones (t value and Pr(>|t|)) . How can the console output format (all columns in one block, figure 3) be kept in the output pdf document?
Code chunk :
```{r model1}
lm1=lm(formula=Long.Term.Debt~.,data=donnees[,-c(1:3)])
summary(lm1)
```
The rendered output in the pdf document :
Fig. 1: A first block containing 2 first columns
Fig. 2: Another block containing 2 remaining columns
Desired output :
Fig. 3: Console output (one block containing all columns)
I have, fruitlessly, tried increasing the display area of the output and decreasing the font size as follows:
Reducing font size :
\tiny
```{r model1}
lm1=lm(formula=Long.Term.Debt~.,data=donnees[,-c(1:3)])
summary(lm1)
```
Setting display area size:
```{r model1, fig.width=80, fig.height=8}
lm1=lm(formula=Long.Term.Debt~.,data=donnees[,-c(1:3)])
summary(lm1)
```
Thanks in advance.
Upvotes: 1
Views: 392
Reputation: 3683
You can use knitr::kable()
and kableExtra()
to show the summary of the result in a more elegant way. The output of the following code is treated as a table. So, its table number is automatically generated if you are using bookdown
, too.
```{r summary}
library(knitr) # for kable()
library(knitrExtra) # for further customisation of the kable() output
library(magrittr) # for the pipe %>%, press "Ctrl/Cmd + Shift + m"
kable(summary(lm1)$coefficient[, 0:4], # by 0:4, you can select the columns from variable names to p-values
digits = 2, # You can reduce the digit number
booktabs = TRUE, # If false, you will get a lattice-like table
caption = 'Coefficients (2 not defined because of sigularities)'
) %>%
kable_styling(font_size = 7) # You can change the font size here
```
Upvotes: 1