You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to draw a few transparent images over my ggplot. I wish to position the transparent image at the very bottom left of the plot. I used x = 0 and y = 0 to position this transparent image. However draw_image() somehow does not recognise transparency and instead positions the bottom left corner of the entire image at those co-ordinates (first plot below).
To try and improve this, I tried the image_trim function of the magick package. However, even here the left-most part (in this case the blue dice) is not quite at x = 0 (second plot below). I understand there is an hjust option, but I am running this operation for hundreds of images and cannot define the hjust in every case.
Is there a way of getting the true left most edge of a transparent image to x = 0?
Thank you
library(cowplot,quietly=T)
#> #> ********************************************************#> Note: As of version 1.0.0, cowplot does not change the#> default ggplot2 theme anymore. To recover the previous#> behavior, execute:#> theme_set(theme_cowplot())#> ********************************************************
library(ggplot2,quietly=T)
##basic version
ggplot(data.frame(x=0:3, y=0:3), aes(x, y)) +
geom_point(size=3) +
draw_image("https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png",x=0,y=0)
The problem is not the transparency, it's the aspect ratio of the image and how that interacts with the way images are placed. There is no easy fix, and a proper fix would require an entirely different placement API. Maybe look into the ggimage package and see if that better fits your needs.
This is now possible in the development version, via additional paramters halign and valign (which in most cases should have the same values as hjust and vjust).
I am trying to draw a few transparent images over my ggplot. I wish to position the transparent image at the very bottom left of the plot. I used x = 0 and y = 0 to position this transparent image. However draw_image() somehow does not recognise transparency and instead positions the bottom left corner of the entire image at those co-ordinates (first plot below).
To try and improve this, I tried the image_trim function of the magick package. However, even here the left-most part (in this case the blue dice) is not quite at x = 0 (second plot below). I understand there is an hjust option, but I am running this operation for hundreds of images and cannot define the hjust in every case.
Is there a way of getting the true left most edge of a transparent image to x = 0?
Thank you
Created on 2019-08-29 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: