Adding a statistics table to the bottom of a ggplot, geom_bar chart in R

S. Braun

I am currently trying to create a plot that has a barchart of coefficients in the top 7/8 of the plot, and a table with statistics in the bottom 1/8. After creating the plot, I save it to a pdf file, which I've been doing with ggsave() and would like to keep that functionality. The program was originally built for just the barcharts, and I am adding in the statistics table.

I am at a loss on how to make this happen, or if I'm even thinking of it the right way.

Initially, I attempted:

  tablestats <- grid.table(stats, rows = NULL)
  grid.arrange(plt, tablestats, nrow = 2)

But I can't have a non grob in the above function.

Then I tried:

  layout(matrix(c(1, 1, 1, 1, 1, 1, 2, 2, 2), 3, 3, byrow = TRUE))
  plt <- plt + tablestats
  print(plt)

But this only plots the barchart.

I've also tried the par(mfrow()) method, but it seemingly ignores the table when plotting.

Does anyone have any advice on how to build something like this or similar? Ideal plot layout

Luis Bento

I think the problem here is that you have to use tableGrob() to define tablestats and not grid.table().

As stated in R: gridExtra - How to plot a Summary as table? :

To combine different tables / plots using grid.arrange they need to be grobs (grid GRaphcal OBjects). So you cannot pass the results from grid.table to grid.arrange as it is not a grob (it actually plots the tableGrob directly). For this you need to pass the tableGrob.

After that you can use grid.arrange() as you did.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Change bar plot colour in geom_bar with ggplot2 in r

How to put labels over geom_bar for each bar in R with ggplot2

ggplot's geom_text() labelling of pie chart hides the pie made by geom_bar()

R - ggplot2 'dodge' geom_step() to overlap geom_bar()

Proportion with ggplot geom_bar

Removing points from geom_bar legend ggplot r

using multiple variables in geom_bar with ggplot at same X (R)

How to switch between geom_line and geom_bar visualization in ggplot2 in Shiny - R

Ggplot geom_bar for large dataset in R

ggplot grouped geom_bar - adding labels of factor categories to the x-axis label

Adding labels to individual % inside geom_bar() using R / ggplot2

Custom colors for discrete values in geom_bar in ggplot R

ggplot2. How to make geom_bar stacked chart y-range 0-100%?

Adding arrows (or image of arrow) onto bar chart in plotly or ggplot in R?

R ggplot - ecdf chart - adding table with summary stats inside/outside plot area

Adding a bar chart to a ggplot2 legend

R: ggplot2 geom_text data labels for binned geom_bar

Adding output of print function to ggplot chart - r

R: ggplot geom_bar fill order not following levels

multivariate bar chart in R ggplot

Adding layer of interpolated values to ggplot chart in R

ggplot bar chart (geom_bar) to use start and end point from df

bar chart R geom_bar changing legend and x axis

r ggplot2 round off geom_text values for geom_bar

R ggplot2 geom_bar add labels with % sign

R ggplot2 change geom_bar to a single color

In ggplot geom_bar, the y axis labels are cluttered at the bottom of bar chart

How to add bottom lines to geom_bar groups in R

R & ggplot2: 100% geom_bar + geom_line for average using secondary y axis