如果我有以下数据框,名为result
> 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文件?
设定有效数字的额外分数。
答案 0 :(得分:8)
我会使用 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")
@
答案 1 :(得分:7)
对于表格方面,我会想到xtable包,因为它可以生成LaTeX输出(您可以通过Sweave用于专业报告)以及html。
如果你将Sweave中的内容与花式图表结合起来(请参阅ggplot示例的其他问题),那么你几乎就在那里。
答案 2 :(得分:2)
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()
答案 3 :(得分:0)
无法评论制作一个漂亮的表格,但要设置有效的数字,最容易做的事情(对于这个示例数据,请注意)将名称移动到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.
这不是一个非常强大的解决方案 - 我认为,非唯一名称值会破坏它,就像其他非数字列一样。但是为了制作一个像你的例子一样的表格,它可以解决问题。