title: Customize a bar plot - aligning bars with a table below the chart
body: <p>Hope this is not out of topic.</p>
  
  <p>I try to customize the code from <a href="https://stackoverflow.com/a/44358658/8088458">this</a> great answer using additional data:</p>
  
  <pre><code>df &lt;- structure(list(year = 1998:2007, work = c(0L, 4L, 0L, 1L, 0L, 0L, 1L, 2L, 2L, 3L), confid = c(0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 3L, 0L), jrs = c(0L, 1L, 0L, 0L, 1L, 9L, 6L, 4L, 21L, 2L)), .Names = c("year", "work", "confid", "jrs"), class = "data.frame", row.names = c(NA, -10L))
  
  library(ggplot2)
  library(reshape)
  md &lt;- melt(df, id=(c("year")))
  
  library(grid)
  library(gridExtra)
  
  # Function to extract legend
  # https://stackoverflow.com/a/13650878/496488
  g_legend &lt;- function(a.gplot){
    tmp &lt;- ggplot_gtable(ggplot_build(a.gplot))
    leg &lt;- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
    legend &lt;- tmp$grobs[[leg]]
    return(legend)}
  
  p = ggplot(data=md, aes(x=year, y=value, fill=variable) ) + 
    geom_bar(stat="identity")+ 
    #theme(axis.text.x=element_text(angle=90, vjust=0.5, hjust=0.5))+ 
    ggtitle("Score Distribution") +
    labs(fill="")
  
  # Extract the legend as a separate grob
  leg = g_legend(p)
  
  # Create a table grob
  tab = t(df)
  tab = tableGrob(tab, rows=NULL)
  tab$widths &lt;- unit(rep(1/ncol(tab), ncol(tab)), "npc")
  
  # Lay out plot, legend, and table grob
  grid.arrange(arrangeGrob(nullGrob(), 
                           p + guides(fill=FALSE) + 
                             theme(axis.text.x=element_blank(),
                                   axis.title.x=element_blank(),
                                   axis.ticks.x=element_blank()),
                           widths=c(1,8)), 
               arrangeGrob(arrangeGrob(nullGrob(),leg,heights=c(1,10)),
                           tab, nullGrob(), widths=c(6,20,1)),
               heights=c(4,1))
  </code></pre>
  
  <p>I tried to change the numbers at the end but I receive again the same results. The table is smaller than the graph and the bars at the graph are not in the right position.</p>
  
  <p>How could I customize the numbers at the end?</p>
  
  <p>Here a screenshot of what I see:
  <a href="https://i.stack.imgur.com/DVgPq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DVgPq.png" alt="enter image description here"></a></p>
  
  <p>In the image 1 I checked because should the bar be in the same line with 1999. As it is now it seems to 2 years. 2 in image shows the table with must have the same width with the plot and the years should be down from every corresponded bar.</p>