【问题标题】:How can I produce report quality tables from R?如何从 R 生成报告质量表?
【发布时间】:2010-11-27 07:39:36
【问题描述】:

如果我有以下称为结果的数据框

> result
     Name       CV      LCB       UCB
1  within 2.768443 1.869964  5.303702
2 between 4.733483 2.123816 18.551051
3   total 5.483625 3.590745 18.772389

> dput(result,"")
structure(list(Name = structure(c("within", "between", "total"
), .rk.invalid.fields = list(), .Label = character(0)), CV = c(2.768443, 
4.733483, 5.483625), LCB = c(1.869964, 2.123816, 3.590745), UCB = c(5.303702, 
18.551051, 18.772389)), .Names = c("Name", "CV", "LCB", "UCB"
), row.names = c(NA, 3L), class = "data.frame")

很好地呈现这些数据的最佳方式是什么?理想情况下,我想要一个可以粘贴到报告中的图像文件,或者可能是一个 HTML 文件来表示表格?

设置有效数字的加分。

【问题讨论】:

    标签: r reporting presentation sweave


    【解决方案1】:
    library(ggplot2)
    ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_errorbar() + geom_point()
    ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_pointrange()
    

    【讨论】:

      【解决方案2】:

      对于表格方面,我想到了xtable 包,因为它可以生成 LaTeX 输出(您可以通过 Sweave 将其用于专业报告)以及 html。

      如果您在 Sweave 中将其与精美的图表结合起来(请参阅其他问题以获取 ggplot 示例),您就差不多完成了。

      【讨论】:

        【解决方案3】:

        我会使用 xtable。我通常将它与 Sweave 一起使用。

        library(xtable)
        d <- data.frame(letter=LETTERS, index=rnorm(52)) 
        d.table <- xtable(d[1:5,])
        print(d.table,type="html")
        

        如果你想在 Sweave 文档中使用它,你可以这样使用它:

        <<label=tab1,echo=FALSE,results=tex>>=
        xtable(d, caption = "Here is my caption", label = "tab:one",caption.placement = "top")
        @
        

        【讨论】:

        • 我没有勇敢面对乳胶和编织的世界。我使用 openoffice write 和 Google Docs。如何将 xtable 用于这些输出之一?
        • 是的。查看 odfweave。如果您想尝试一下,还有一个名为 r2html 的包,虽然我没有取得那么成功。
        【解决方案4】:

        要设置有效数字,最简单的方法(对于此示例数据,请注意)是将 Name 移动到 rownames 并舍入整个内容。

        #Set the rownames equal to Name - assuming all unique
        rownames(result) <- result$Name  
        #Drop the Name column so that round() can coerce
        #result.mat to a matrix
        result.mat <- result[ , -1]       
        round(result.mat, 2) #Where 2 = however many sig digits you want.            
        

        这不是一个非常强大的解决方案 - 我认为非唯一的 Name 值会破坏它,就像其他非数字列一样。但是要生成像您的示例这样的表格,它就可以了。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2010-10-15
          • 1970-01-01
          • 1970-01-01
          • 2013-07-23
          • 1970-01-01
          • 2012-06-27
          • 2013-02-15
          相关资源
          最近更新 更多