title: Image transparency is affected (transparent) once alpha is modified! ggplot2
body: <p>I am trying to add the following image to this barchart, however, as you can see when I knight it to produce a pdf the image gets transparent! with that alpha of .45. If I set alpha to 1 then it shows as it should be!</p>
  <p>In this example I am using alpha only to make the second dodge barchart transparent, but the included png, should be 100% in color not faded! Do you know of any way to achieve this, i still want those sets of bars faded away with alpha but the image intact.</p>
  <p>Note that if you just run this in your Rmarkdown the image in the preview looks excellent, the problem comes when we knit and produce the pdf!</p>
  <p>Please Help</p>
  <p>This is the faded unwanted result of the horse image on the chart when knitr to pdf:</p>
  <p><a href="https://i.stack.imgur.com/RTuOz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RTuOz.png" alt="enter image description here" /></a></p>
  <p>The actual icon is:
  <a href="https://i.stack.imgur.com/U7xxb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U7xxb.png" alt="enter image description here" /></a></p>
  <p>The code I used is here:</p>
  <pre><code>library(ggplot2)
  library(reshape2)
  library(grid)
  
  #Create DataFrame
  x &lt;- c(5,17,31,9,17,10,30,28,16,29,14,34)
  y &lt;- c(39,6,3,4,1,6,7,2,9,10,3,4)
  day &lt;- c(&quot;d1&quot;,&quot;cd2&quot;,&quot;d3&quot;,&quot;d4&quot;,&quot;d5&quot;,&quot;d6&quot;,&quot;d7&quot;,&quot;d8&quot;,&quot;d9&quot;,&quot;d10&quot;,&quot;d11&quot;,&quot;d12&quot;)
  df1 &lt;- data.frame(x, y, day)
  
  #Sort the table according to x values
  df1$day &lt;- factor(df1$day, levels = df1[order(-df1$x), 3])
  
  #for each day (e.g. 1) you will have all combinations of x and y (e.g. day = 1, x = 5, y = 5), (e.g. day = 12, x=34, y=4). variable becomes x and y, and value becomes the value of either x or y.
  df2 &lt;- melt(df1, id.var=&quot;day&quot;, measure.var=c(&quot;x&quot;,&quot;y&quot;))
  #head(df2)
  
  #Image
  img &lt;- readPNG(&quot;imgs/unnamed.png&quot;)
  g &lt;- rasterGrob(img, interpolate=TRUE)
  
  
  barcolors &lt;- c(&quot;#428953&quot;, &quot;#CE2929&quot;, &quot;#A3DD57&quot;, &quot;#77E599&quot;, &quot;#5675D6&quot;, &quot;#65ECEF&quot;, &quot;#FF8B07&quot;, &quot;#D0B100&quot;, &quot;#636363&quot;, &quot;#D0B100&quot;, &quot;#CE2929&quot;, &quot;#428953&quot;)
  
  ggplot(df2, aes(x=day, y=value)) + 
      geom_bar(aes(fill=day, alpha=variable), stat=&quot;identity&quot;, width = .75, position = position_dodge(width=.8)) +
      scale_alpha_manual(values=c(1, .45)) +
      scale_fill_manual(values= barcolors) +
      theme_bw() + 
      theme( panel.grid.major.x = element_blank(),
         legend.position=&quot;none&quot;,
         legend.text=element_text(size=14),
         legend.title = element_blank(),
         axis.title.x = element_blank()) +
      annotation_custom(g, xmin=.7, xmax=1.3, ymin=35, ymax=40) + ylim(0,40)   
  </code></pre>