微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用观星台使色谱柱更宽?

如何解决使用观星台使色谱柱更宽?

因此,我正在使用观星仪制作具有回归系数的表格,但我不知道如何使列变宽。

stargazer(fit2,fit3,type="html",dep.var.labels=c(""),covariate.labels=c("PVI","Research Level","Minority Serving Institution","Women's College","Prestige","Control Level (private = 1)","Intercept 1","Intercept 2"),keep.stat = "all",title =  "Table 1. Ordered Logit Estimates of Chicago Statement Endorsement",ord.intercepts = TRUE,column.sep.width = "20pt",out="models.htm")

这是我的代码。不管我为column.sep.width设置什么值,列都不会移动。

解决方法

带有stargazer

type="html"返回html文本。您可以插入html样式,例如,固定列宽,例如<col width="20">...<col width="20">


library(stargazer)

linear.1 <- lm(rating ~ complaints + privileges + learning 
               + raises + critical,data=attitude)
linear.2 <- lm(rating ~ complaints + privileges + learning,data=attitude)

attitude$high.rating <- (attitude$rating > 70)
probit.model <- glm(high.rating ~ learning + critical + advance,data=attitude,family = binomial(link = "probit"))

tbl <- stargazer(linear.1,linear.2,probit.model,title="Regression Results",type="html")

set_html_tbl_widths <- function(stargazer_html_obj,width_left=30,width_cols=rep(20,num_cols),num_cols=3,filename=NULL) {
  html_line <- c(paste0('<col width=',as.character(width_left),'>'))
  num_cols <- length(width_cols)
  for (col in 1:num_cols) {
    html_line <- append(html_line,paste0('<col width=',as.character(width_cols[col]),'>'))
  } 
  new_html <- c(stargazer_html_obj[1:2],html_line,stargazer_html_obj[3:length(stargazer_html_obj)])

  if (!is.null(filename)) {
    write(new_html,file=filename)
  }
  return(new_html)
}

set_html_tbl_widths(tbl,filename="models.html")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。