Chris Martin Chris Martin - 3 years ago 207
R Question

grid.arrange() plot and table are overlapping

this is my first post on Stack so any help would be appreciated. If I need to rephrase my question or be more specific please let me know.

I am attempting to create a figure containing both a plot, and a table relating to that plot. I am able to produce the plot but my table is too long and subsequently overlaps with my bar chart. Below is dummy code to reproduce the problem.

My Question is this. Is there any way to split my table into n parts so that it fits neatly underneath my bar chart? I have several data frames to do this for of varying sizes, so a manual row-wise sub-setting to produce multiple tables is not preferred. Any help would be appreciated.

catg <- rnorm(50)
amts <- rnorm(50)
data <- data.frame(catg,amts)

plt1 <- ggplot(data,aes(x=catg,y=amts))+
geom_bar(stat="identity", width=0.1)

tbl1 <- tableGrob(amts)


Answer Source

I don't know what you have in mind but maybe reshape those values into N columns (and round the numbers)?

grid.table(matrix(round(amts,3), ncol=5))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download