Shashivydyula
Shashivydyula

Reputation: 85

Alternative for ggimage (geom_image) for Kaggle

I am trying to plot a bar plot for a movie dataset. I want to plot the movie image/icon at the top of the bar for each movie in a plot. I am using the following code to achieve this in R studio for PC:


top_voted <- animated_movies[, .(title, vote_count)][order(-vote_count)][1:10]
top_voted$title <- factor(top_voted$title, levels = top_voted$title)
top_voted$image_url<-c("https://lumiere-a.akamaihd.net/v1/images/p_insideout_19751_af12286c.jpeg",
                       "https://upload.wikimedia.org/wikipedia/en/0/05/Up_%282009_film%29.jpg",
                       "https://m.media-amazon.com/images/M/MV5BZmYxZjg3OWEtNzg5Yi00M2YzLWI1YzYtYTQ0NTgwNzhjN2E1XkEyXkFqcGdeQXVyNDUyOTg3Njg@._V1_.jpg,",
                       "https://m.media-amazon.com/images/M/MV5BYjQ5NjM0Y2YtNjZkNC00ZDhkLWJjMWItN2QyNzFkMDE3ZjAxXkEyXkFqcGdeQXVyODIxMzk5NjA@._V1_.jpg",
                       "https://lumiere-a.akamaihd.net/v1/images/p_walle_19753_69f7ff00.jpeg",
                       "https://lumiere-a.akamaihd.net/v1/images/p_monstersinc_19751_55afa07a.jpeg",
                       "https://m.media-amazon.com/images/M/MV5BMDU2ZWJlMjktMTRhMy00ZTA5LWEzNDgtYmNmZTEwZTViZWJkXkEyXkFqcGdeQXVyNDQ2OTk4MzI@._V1_.jpg",
                       "https://resizing.flixster.com/-XZAfHZM39UwaGJIFWKAE8fS0ak=/v3/t/assets/p15766_p_v8_ab.jpg",
                       "https://upload.wikimedia.org/wikipedia/en/2/27/The_Incredibles_%282004_animated_feature_film%29.jpg",
                       "https://images.moviesanywhere.com/5948f139cd669fb5984d2c782e7678be/99cedd1f-ae78-4026-a3e8-b79840b71cbc.jpg")

The structure (dput) of the top_voted is:

structure(
  list(
    title = structure(
      1:10,
      levels = c(
        "Inside Out",
        "Up",
        "Finding Nemo",
        "Coco",
        "WALL·E",
        "Monsters, Inc.",
        "Toy Story",
        "The Lion King",
        "The Incredibles",
        "Shrek"
      ),
      class = "factor"
    ),
    vote_count = c(
      19463L,
      18857L,
      18061L,
      17742L,
      17446L,
      17189L,
      17152L,
      16991L,
      16584L,
      15765L
    ),
    image_url = c(
      "https://lumiere-a.akamaihd.net/v1/images/p_insideout_19751_af12286c.jpeg",
      "https://upload.wikimedia.org/wikipedia/en/0/05/Up_%282009_film%29.jpg",
      "https://m.media-amazon.com/images/M/MV5BZmYxZjg3OWEtNzg5Yi00M2YzLWI1YzYtYTQ0NTgwNzhjN2E1XkEyXkFqcGdeQXVyNDUyOTg3Njg@._V1_.jpg",
      "https://m.media-amazon.com/images/M/MV5BYjQ5NjM0Y2YtNjZkNC00ZDhkLWJjMWItN2QyNzFkMDE3ZjAxXkEyXkFqcGdeQXVyODIxMzk5NjA@._V1_.jpg",
      "https://lumiere-a.akamaihd.net/v1/images/p_walle_19753_69f7ff00.jpeg",
      "https://lumiere-a.akamaihd.net/v1/images/p_monstersinc_19751_55afa07a.jpeg",
      "https://m.media-amazon.com/images/M/MV5BMDU2ZWJlMjktMTRhMy00ZTA5LWEzNDgtYmNmZTEwZTViZWJkXkEyXkFqcGdeQXVyNDQ2OTk4MzI@._V1_.jpg",
      "https://resizing.flixster.com/-XZAfHZM39UwaGJIFWKAE8fS0ak=/v3/t/assets/p15766_p_v8_ab.jpg",
      "https://upload.wikimedia.org/wikipedia/en/2/27/The_Incredibles_%282004_animated_feature_film%29.jpg",
      "https://images.moviesanywhere.com/5948f139cd669fb5984d2c782e7678be/99cedd1f-ae78-4026-a3e8-b79840b71cbc.jpg"
    )
  ),
  row.names = c(NA,-10L),
  class = c("data.table", "data.frame"),
  .internal.selfref = < pointer:0x00000199ac3d2d70 >
)

plot_top_voted <- ggplot(data = top_voted, aes(
  x = reorder(title, -vote_count),
  y = vote_count,
  fill = title
)) +
  geom_bar(stat = "identity") +
  labs(fill = "Title",
       title = "Top 10 Voted Movies",
       x = "Title",
       y = "Vote Count")+
  geom_image(aes(image=image_url), size=0.1, position = position_nudge(y=10))+
  theme(axis.text = element_text(size = 12, angle = 54, hjust = 1),
        plot.title = element_text(size = 16, hjust=0.5))



plot_top_voted

The above code works perfectly in my R studio. However geom_image does not work in Kaggle as they don't support ggimage package.

Is there any alternate way to achieve this?

Upvotes: 0

Views: 110

Answers (0)

Related Questions