How to print / plot a table in #R?

2

Consider:

 dat <-  matrix(c(1000, 100, 10000, 10000,3.145,1700.42), 2)

Where dat refers to loop result data, generating a new dat for each loop. I need to present these results, so I thought I'd export dat to a tabular format or an image.

How can I generate this information / result in R as an already formatted table (margin and header lines) or image, is it possible?

    
asked by anonymous 03.04.2016 / 06:59

1 answer

1

Using this as a reference from SOen , I arrived to the following:

First of all, evaluate well if you really want to do this. Text and formatting are much more flexible and easier to modify than an image.

A simple way to do what you want is to use the gridExtra package:

library("gridExtra")

dat <- matrix(c(1000, 100, 10000, 10000,3.145,1700.42), 2)
grid.table(dat)

Result:

Thetableranoutoftitlesbecauseitisanarraywithnocolnames.Youcancustomizetheimage,butthesyntaxisnotsosimple.Toseewhatcanbedone,youneedtoinvestigatethedefaultthemevalues:

>ttheme_default()$core$core$fg_fun...$core$fg_params$core$fg_params$parse[1]FALSE$core$fg_params$col[1]"black"

$core$fg_params$fontsize
[1] 12
...

You can customize the theme as follows:

mytheme <- ttheme_default()
mytheme$core$bg_params$fill <- c("yellow", "pink")
grid.table(dat, theme = mytheme)

That would lead to this result:

If you really want to invest in this, take a look at the help ( ?grid.table ) and default theme to see what can be modified.

    
06.04.2016 / 03:35