Transfor a Gif to a grob in R to use with annotation_custom in a ggplot
<p>I am trying to import a gif and turn it into a grob to use it with the function annotation_custom in a ggplot, so far I imported it and have been able to turn it into an image.</p>

<p>So far this is what I have:</p>

<pre><code>library(caTools)
require(ggplot2)
require(grid)
require(gridExtra)
y &lt;- read.gif("http://blog.helpingadvisors.com/wp-content/uploads/2011/01/basketballcourt.gif")
</code></pre>

<p>and I get a list, so far I have been able to plot it:</p>

<pre><code>image(y$image, col=y$col, main=y$comment, asp=1)
</code></pre>

<p>But I have tried to transform it to a grob:</p>

<pre><code>a &lt;- rasterGrob(image(y$image, col=y$col, main=y$comment, asp=1))
</code></pre>

<p>or try</p>

<pre><code>raster(image(y$image, col=y$col, main=y$comment, asp=1))
</code></pre>

<p>and then save it as a grob, but since image returns class NULL it does not work.</p>

<p>I've also tried to use the matrix from y, but it gets really strange colours:</p>

<pre><code>plot(raster(y$image))
</code></pre>

<p>and I really need the original colours</p>