2

This post is an extension from this one

I want to know if I can use the ggtextures and ggplot packages to have two images side by side on a bar graph.

I've used ggtextures to have one image per bar, and it looks like this so far: enter image description here

What I'm trying to do now is to add the NBA team logo next to the rookie pictures. The code for the graph below is something like this:

a5 %>%
  ggplot(aes(x = reorder(Player,
                         PER),
             y = PER,
             fill = Player,
             image = c(image))) +
  geom_bar(stat = "identity") +
  geom_isotype_col(
    img_height = grid::unit(1, "null"), img_width = NULL,
    ncol = 1, nrow = 1, hjust = 1, vjust = 0.5
  ) +
              coord_flip() +
              theme_minimal() +
              xlab("Player") +
              ylab(PER) +
              theme(legend.position = "none")

I have an image column in my data to correspond to the rookie picture, and I also have another column to correspond to the team the rookie plays in. Is there any way I can change

image = c(image)))

to something like c(image, NBAteams), and get it to work with the line,

 geom_isotype_col(
        img_height = grid::unit(1, "null"), img_width = NULL,
        ncol = 1, nrow = 1, hjust = 1, vjust = 0.5
      )

?

Pedro Guizar
  • 357
  • 2
  • 9
  • I don't know if you found a solution, but my guess if it does what you want, you could work out how to put the images side by side (i.e. so they become one single image) and then place the one image into your plot. Very cool plot btw! – stevec Apr 25 '20 at 10:24
  • 1
    Add suggested by @stevec, this can be made using `magick::image_append`. I suggest adding a new column with `mutate` and the mentioned function to combine both images. – JacintoCC Oct 11 '21 at 11:09

0 Answers0