简体   繁体   English

如何在R中使用值列和标签列可视化data.frame?

[英]How can I visualize a data.frame with a values column and a label column in R?

I'm using the pdf command and ggplot2 to create couple different types of graphs and while I'm at it I'd like to throw in some simple tables (with, for example, column labels being coefficient names and rows having values) but I'm not sure to make a "plot" out of that without going separately into excel to make a table (but then I don't know how to insert it into the pdf I generate with R) 我正在使用pdf命令和ggplot2创建几个不同类型的图形,而在此过程中,我想抛出一些简单的表(例如,列标签为系数名称,行具有值),但是我不确定在不单独进入excel来制作表格的情况下做出“绘图”(但是后来我不知道如何将其插入用R生成的pdf中)

For example suppose I've got a data.frame like this one: 例如,假设我有一个像这样的data.frame

set.seed(1)
foo = data.frame(val1=rnorm(5), val2=rnorm(5), columnLabels=c('A','B','C','D','F'))

Is there a simple way to "plot" a simple table with those column labels, with row labels like c('Val 1', 'Val2') and with the corresponding values? 是否有一种简单的方法来“绘制”具有这些列标签,具有c('Val 1','Val2')等行标签以及相应值的简单表?

The tableGrob() function in GridExtra may help. GridExtra中的tableGrob()函数可能会有所帮助。

> library(grid)
> library(gridExtra)

> set.seed(1)
> d = data.frame(val1=rnorm(5), val2=rnorm(5), columnLabels=c('A','B','C','D','F'))

> # transpose dataframe to get requested columns/rows
> rownames(d) <- d$columnLabels
> d$columnLabels <- NULL
> dt <- t(d)

> g <- tableGrob(dt)
> grid.newpage()
> grid.draw(g)

Which is basically 基本上是

> example(tableGrob)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何有效地更新R data.frame列值? - How to update R data.frame column values efficiently? R如何使用另一个data.frame中的值更新data.frame中的列 - R How to update a column in data.frame using values from another data.frame 如何基于data.frame的列表列创建标签/工具提示 - How can I create a label/tooltip based on a list column of a data.frame 如何对 R 中的 data.frame 或 tibble 列中的 NA 值的总数求和,并按月和年对它们进行分组 - How can I sum the totals of NA values in a data.frame or tibble column in R and group them by Month and Year 如何在 R Data.frame 中使用 if/then 改变列 - How to mutate a column with if/then in R Data.frame 如何替换data.frame中的列值? - How do I replace column values in data.frame? 如何求和 data.frame 列值? - How to sum data.frame column values? 检查 R data.frame 列在另一列中是否有相等的值 - Check R data.frame column for equal values in another column 是否有一个R包具有data.frame的通用类,其中列可以是数组(或者我如何定义这样的类)? - Is there an R package with a generalized class of data.frame in which a column can be an array (or how do I define such a class)? R-如何将一个空的POSIXct列添加到已经存在的data.frame / tibble中? - R - How can I add an empty POSIXct column to a data.frame / tibble which already exists?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM