how to make a plot bakcground image (annotation_custom) fit the full height and width of the plot ?

96 views
Skip to first unread message

Divin Sorcier

unread,
Feb 14, 2016, 6:44:35 PM2/14/16
to ggplot2

Is there a way for an annotation_custom to match perfectly and automatically the width AND height of the plot ?

See provided file for a sample of the issue. The seine.png file does not match height. I would like ggplot to stretch the image.


issue.R
seine.png

Sagar G

unread,
Aug 22, 2016, 4:54:14 PM8/22/16
to ggplot2
Hi Divin, I was looking to solve the same problem, were able to figure how to fix this ? 

Thanks,
Sagar

Crump, Ron

unread,
Aug 23, 2016, 6:36:21 AM8/23/16
to Sagar G, ggplot2, Divin Sorcier
Hi Sagar,

>Hi Divin, I was looking to solve the same problem, were able to figure
>how to fix this ?

I've had a very quick look at Divin's original example (which I've
attached in case anyone has deleted it) and I think I've got a simple
solution. Try replacing the call to annotation_custom(r) with:

annotation_raster(img,-Inf,Inf,-Inf,Inf,interpolate=TRUE)

I think that does it. On a superficial comparison with the seine.png
image, it looks right, but the alteration to the aspect ratio and
fuzziness makes it a bit harder to tell.

It also means you don't need to convert the image to a rastergrob either.

Ron.

seine.png
issue.r

Sagar G

unread,
Aug 23, 2016, 10:43:37 AM8/23/16
to Crump, Ron, ggplot2, Divin Sorcier
Hi Ron, 
Thanks for replying, I was able to fix this.
I tried the same using: annotation_raster and yes, does not require you to convert image into rastergrob.
Once again thanks for your help !

Thanks,
Sagar
--
Regards,
Sagar
Reply all
Reply to author
Forward
0 new messages