0

I like to use some icons and images in my ggplot, thus use the ggimage package. I can make it work with local or online images in .png format. But it does not work with svg such as https://raw.githubusercontent.com/ionic-team/ionicons/main/src/svg/hourglass.svg Initially I also was trying a geom_icon() layer.

library("ggplot2")
library("ggimage")

mtcars %>% 
  mutate(am = factor(am)) %>% 
  group_by(am) %>% 
  summarise(avg_mpg = mean(mpg)) %>% 
  mutate(image = c("https://www.r-project.org/logo/Rlogo.png",
              "https://jeroenooms.github.io/images/frink.png")) %>% 
  ggplot(aes(x=factor(am), y=avg_mpg)) + 
  geom_col(width = 0.5) + 
  geom_image(aes(image=image), size=.2) + 
  theme_minimal()

enter image description here

Marco
  • 2,368
  • 6
  • 22
  • 48
  • Could you please share what not working? When I use the link it shows the icon. – Quinten May 04 '23 at 15:35
  • 1
    Works fine for me, too: https://i.stack.imgur.com/2XwQg.png. Only had to manually install `rsvg`. If it matters I'm on a Mac. – stefan May 04 '23 at 16:05
  • Thank you, I missed the `rsvg` package. Obviously did not install all dependencies. – Marco May 08 '23 at 12:44

1 Answers1

0

Install rsvg package with all dependencies.

Marco
  • 2,368
  • 6
  • 22
  • 48