我正在远离 Word/Excel 表格并尝试在 中生成表格R .我有一个数据框,我想简单地将其打印为绘图,同时能够对单元格进行着色/着色并通常具有美感。
x <- data.frame(row.names=paste("Name",1:10))
x[,1] <- 1:10
x[,2] <- sample(1:100,10)
x[,3] <- sample(LETTERS[1:26],10)
colnames(x) <- c("Value 1", "Value 2", "Label")
View(x)
提供我想要的表格的确切格式,就像一个可保存的图。我试过
plot(x,type="h")
但是收到一个错误:
Error in plot.default(...) : formal argument "type" matched by multiple actual arguments
我已经看到如何输出具有两列的表格,但如何按原样绘制数据框?用于显示如何将该表格粘贴在我创建的另一个散点图下方的奖励积分,以便输出 ggsave 具有散点图,该散点图下方有表格。
最佳答案
由于我要获得奖励积分:
#Plot your table with table Grob in the library(gridExtra)
ss <- tableGrob(x)
#Make a scatterplot of your data
k <- ggplot(x,aes(x=x$"Value 1",y=x$"Value 2")) +
geom_point()
#Arrange them as you want with grid.arrange
grid.arrange(k,ss)
如果需要,您可以更改行数、列数、高度等。
祝你好运
http://cran.r-project.org/web/packages/gridExtra/gridExtra.pdf
关于r - 将数据框绘制为表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30794273/