1

I am trying to plot a table with the values from a dataframe. I am not sure of what approach to take using .

I am also trying one approach using ::grid.table() and tableGrob() functions and both are working similarly.

For example: I plot iris as a table using following code

library(gridExtra)
library(grid)
d <- head(iris, 3)
g <- tableGrob(d)
grid.draw(g)

When I plot this data using grid.draw, why I am getting row numbers 1 to 3 along with the table and how can I work on removing these numbers and change font type and background colors. Please guide!

Also guide me to the approach using ggplot2

Your help will be appreciated!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jawairia
  • 295
  • 4
  • 14
  • `grid.draw()` from [tag:grid] ? Please add the usual `require` or `library` calls to your code, and see my suggested edits – tjebo Mar 13 '18 at 07:23
  • yes `grid.draw()` is from grid – Jawairia Mar 13 '18 at 07:24
  • 2
    Have a look at `?tableGrob` – Mikko Marttila Mar 13 '18 at 07:27
  • @Mikko I have already mentioned `tableGrob`. I have an issue that row numbers are appearing along side the table using this approach and I don't want that – Jawairia Mar 13 '18 at 07:28
  • 1
    If you read the manual page, you will notice that the second argument to `tableGrob` controls the printing of row numbers: use `tableGrob(d, rows = NULL)`. On the same page you will also notice that there is a `theme` argument that controls font type etc. – Mikko Marttila Mar 13 '18 at 07:29
  • 1
    If you want to integrate the table in a `ggplot` directly, see: https://stackoverflow.com/questions/12318120/adding-table-within-the-plotting-region-of-a-ggplot-in-r – Mikko Marttila Mar 13 '18 at 07:34
  • @ Mikko thanks row names are removed. I am trying to use base_family arguments but it is giving some errors, I am not sure how can I use it. Also the link you shared is not what I want, I want table as an output and not a graph. – Jawairia Mar 13 '18 at 07:39

0 Answers0