使用 expss 包调整列宽
Adjusting Column Widths with expss Package
我经常使用 expss
并发现它非常有用,但是,在某些情况下,我的列值是不适合默认列宽的长字符串。
例如,下图显示了一个需要加宽的列。 expss
中的哪些 htmlTables()
选项可用于加宽列?
有几种方法可以增加第一列的宽度。尝试
以下之一:
library(expss)
expss_output_viewer()
data(mtcars)
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
cyl = "Number of cylinders",
disp = "Displacement (cu.in.)",
hp = "Gross horsepower",
drat = "Rear axle ratio",
wt = "Weight (1000 lbs)",
qsec = "1/4 mile time",
vs = "Engine",
vs = c("V-engine" = 0,
"Straight engine" = 1),
am = "Transmission",
am = c("Automatic" = 0,
"Manual"=1),
gear = "Number of forward gears",
carb = "Number of carburetors"
)
# straightforward column width adjustment
calc_cro_cpct(mtcars, list(vs, am), list(total(), vs %nest% am)) %>%
htmlTable(., css.cell = c("width: 250px", # first column width
rep("width: 50px", ncol(.) - 1)) # other columns width
)
# row labels padding
calc_cro_cpct(mtcars, list(vs, am), list(total(), vs %nest% am)) %>%
htmlTable(padding.rgroup = paste(rep(" ", 20), collapse = ""))
# disable row grouping
calc_cro_cpct(mtcars, list(vs, am), list(total(), vs %nest% am)) %>%
htmlTable(row_groups = FALSE)
参数 css.cell
和 padding.rgroup
记录在
expss
用于呈现 HTML table 表示的 htmlTable 包(参见
?htmlTable::htmlTable).
我经常使用 expss
并发现它非常有用,但是,在某些情况下,我的列值是不适合默认列宽的长字符串。
例如,下图显示了一个需要加宽的列。 expss
中的哪些 htmlTables()
选项可用于加宽列?
有几种方法可以增加第一列的宽度。尝试 以下之一:
library(expss)
expss_output_viewer()
data(mtcars)
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
cyl = "Number of cylinders",
disp = "Displacement (cu.in.)",
hp = "Gross horsepower",
drat = "Rear axle ratio",
wt = "Weight (1000 lbs)",
qsec = "1/4 mile time",
vs = "Engine",
vs = c("V-engine" = 0,
"Straight engine" = 1),
am = "Transmission",
am = c("Automatic" = 0,
"Manual"=1),
gear = "Number of forward gears",
carb = "Number of carburetors"
)
# straightforward column width adjustment
calc_cro_cpct(mtcars, list(vs, am), list(total(), vs %nest% am)) %>%
htmlTable(., css.cell = c("width: 250px", # first column width
rep("width: 50px", ncol(.) - 1)) # other columns width
)
# row labels padding
calc_cro_cpct(mtcars, list(vs, am), list(total(), vs %nest% am)) %>%
htmlTable(padding.rgroup = paste(rep(" ", 20), collapse = ""))
# disable row grouping
calc_cro_cpct(mtcars, list(vs, am), list(total(), vs %nest% am)) %>%
htmlTable(row_groups = FALSE)
参数 css.cell
和 padding.rgroup
记录在
expss
用于呈现 HTML table 表示的 htmlTable 包(参见
?htmlTable::htmlTable).