简体   繁体   中英

How can I adjust printed summary width with long variable names in R Markdown?

I'm having a weird issue with printing the results of a summary function in R Markdown. I'm compiling an html document of the results of my analysis, but what I'm noticing is that the column of the summary that displays statistical significance is being wrapped around to the next series below the rest of the data rather than forming a single series of rows. Specifically this seems to be driven by the length of a coefficient name that represents the interaction between a grouping variable and a numeric log-transformed independent variable raised to a fractional exponent. However, because my grouping variable has 27 levels it results in a huge amount of wasted space.

The strange thing is looking at the actual print of the summary table it seems like there is plenty of space to keep the significance column in line with the estimate, std. error, t value, and p value. I don't know what is driving it to wrap around. Below is an attached figure showing what it looks like when I knit the code.

显示问题的图像

Below is some code that replicates the issue using the mtcars dataset. I've tested this and it should work with a plain html_document format.

data(mtcars)
data.frame(mtcars)

mtcars$supercalifragilisticexpialidocious1234a<-mtcars$cyl #renaming character to same character length as my data.
mtcars$supercalifragilisticexpialidocious1234b<-mtcars$mpg
summary(lm(supercalifragilisticexpialidocious1234b~supercalifragilisticexpialidocious1234a,data=mtcars))

The reason the character names are so long is that in the actual dataset they represent the results of an interaction coefficient between the scientific name of a taxonomic group (the longest of which is 16 characters long), and an interaction coefficient raising the variable to a fractional exponent. So in reality the coefficient name looks like "groupTaxonname::I(log(var)^(1/2))", it's not a single variable with a monstrously long name. However, the problem with this means that I cannot simply shorten the coefficient names in order to make the table narrower and easier to fit, there is no real abbreviation that can be used for the group names and omitting the rest of the coefficient name would mean potentially inaccurately defining the variables used.

Given this I'm wondering if there is some way to adjust the output of the summary function in R Markdown to produce something like the following:

在此处输入图像描述

Adding options(width=1000) in the same code chunk did the trick for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM