r - 将数据框绘制为表格

标签 r plot

我正在远离 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)

如果需要,您可以更改行数、列数、高度等。

祝你好运
enter image description here

http://cran.r-project.org/web/packages/gridExtra/gridExtra.pdf

关于r - 将数据框绘制为表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30794273/

相关文章:

r - 将 R 中的数据帧转换为 'Python dictionary'

R: map 中带有 spplot 的自定义调色板

Python PyX 绘图 : change axes tick text color

python - 基于列而不是行索引/索引的 Bokeh 链接/刷光

python - 绘图后更改轴

python - Python/Pandas 中的 R 向量语法

r - rstudio 中的knitr按钮

r - 自定义 R 中 image.plot 中的颜色范围

python - Altair 中带有标签值的分层或多面条形图

r - 在 R 中使用 gsub 在子字符串周围插入点