title: R ggplot2: Line overlayed on Bar Graph (from separate data frames)
body: <p>I have a bar graph coming from one set of monthly data and I want to overlay on it data from another set of monthly data in the form of a line.  Here is a simplified example (in my data the second data set is not a simple manipulation of the first):</p>
  
  <pre><code>library(reshape2)
  library(ggplot2)
  
  test&lt;-abs(rnorm(12)*1000)
  test&lt;-rbind(test, test+500)
  colnames(test)&lt;-month.abb[seq(1:12)]
  rownames(test)&lt;-c("first", "second")
  otherTest&lt;-apply(test, 2, mean)
  test&lt;-melt(test)
  otherTest&lt;-as.data.frame(otherTest)
  
  p&lt;-ggplot(test, aes(x=Var2, y=value,  fill=Var1, order=-as.numeric(Var2))) + geom_bar(stat="identity")+
      theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
      panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
      ggtitle("Test Graph") +
      scale_fill_manual(values = c(rgb(1,1,1), rgb(.9,0,0))) + 
      guides(fill=FALSE) +
      theme(axis.text.x = element_text(angle = 45, hjust = 1)) 
  </code></pre>
  
  <p>works great to get the bar graph:
  <a href="https://i.stack.imgur.com/0RCVX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0RCVX.png" alt="enter image description here"></a></p>
  
  <p>but I have tried multiple iterations to get the line on there and can't figure it out (like this):</p>
  
  <pre><code>p + geom_line(data=otherTest,size=1, color=rgb(0,.5,0)
  </code></pre>
  
  <p>Also, if anybody knows how I can make the bars in front of each other so that all you see is a red bar of height 500, I would appreciate any suggestions.  I know I can just take the difference between the two lines of the matrix and keep it as a stacked bar but I thought there might be an easy way to put both bars on the x-axis, white in front of red.  Thanks!</p>