It is traditional, in plotting survival curves, to have a table under the survival plot listing numbers at risk at intervals corresponding to the tick times on the plot. I have found code that lines up plots with similar x ticks and code that lines up tables with similar column names. But I haven't found how to aline an at.risk *table* with the x ticks on a *plot*. The following code generates a plot and a table. I want to be able to align the table columns with the x-axis ticks.

Thanks in advance for any suggestions how I can accomplish this.

library(ggplot2)

library(grid)

library(gridExtra)

df1 <- data.frame(x = 0:10, y = 0:10)

p <- ggplot(df1, aes(x = x, y = y)) + geom_line(col = 'red') +

scale_x_continuous("Number", breaks = 0:9,

limits = c(0, 10))

table1 <- matrix(1:40, nrow = 4)

rownames(table1) <- paste("row", 1:4)

table2 <- tableGrob(table1, rows = rownames(table1),

theme = ttheme_minimal(base_size = 9,

padding = unit(c(0.5, 0.2), 'lines')))

grid.newpage()

b <- arrangeGrob(p, table2,

nrow = 2, heights = unit(c(2, .35),c("null", "null")))

grid.draw(b)