title: How to rotate an image R raster
body: <p>I have code below which saves an image to my pc. I would like to rotate that image by 45,90 and 135 degrees around its center (or bottom left hand corner) and then save as 3 different images. How could I do that?</p>
  
  <pre><code>library(raster)
  r1 &lt;- brick(system.file("external/rlogo.grd", package="raster"))
  x &lt;- crop(r1, extent(0,50,0,50))
  plotRGB(x)
  png(width=50, height=50)
  par(mai=c(0,0,0,0))
  image(x)
  dev.off()
  </code></pre>
  
  <p>---------update1-------------------------</p>
  
  <p>Based upon the accepted answer the working code is as below</p>
  
  <pre><code>library(raster)
  r1 &lt;- brick(system.file("external/rlogo.grd", package="raster"))
  r1
  x &lt;- crop(r1, extent(0,ncol(r1),0,nrow(r1)))
  plotRGB(x)
  
  x1 &lt;- 0:ncol(x)
  y1 &lt;- 0:nrow(x)
  z &lt;- matrix(1, nrow=length(x1), ncol=length(y1))
  
  col.mat &lt;- t(apply(matrix(rgb(getValues(x)/255), nrow=nrow(x), byrow=TRUE), 2, rev))
  
  # Rotate 45 degrees
  persp(x1, y1, z, zlim=c(0,2), theta = 20, phi = 90, 
        col = col.mat, scale=FALSE, border=NA, box=FALSE)
  png("SaveThisPlot.png")
  persp(x1, y1, z, zlim=c(0,2), theta = 20, phi = 90, 
        col = col.mat, scale=FALSE, border=NA, box=FALSE)
  dev.off()
  </code></pre>