0

I'm trying to plot some images (football logos) as my y-axis labels using ggtext. However, I get the below error message when I try and view the plot.

Error in function (type, msg, asError = TRUE) :

I've tried following some online examples on how to plot images using ggtext, so I'm a bit stuck on what is causing the error. Any help with this will be appreciated.

Thank you.

library(tidyverse)
library(ggalt)
library(ggtext)

data <- tibble(
  label = c("https://a.espncdn.com/i/teamlogos/nfl/500/tb.png",
            "https://a.espncdn.com/i/teamlogos/nfl/500/no.png",
            "https://a.espncdn.com/i/teamlogos/nfl/500/pit.png",
            "https://a.espncdn.com/i/teamlogos/nfl/500/ind.png",
            "https://a.espncdn.com/i/teamlogos/nfl/500/gb.png"),
  x1 = c(0.219, 0.169, 0.103, 0.193, 0.345),
  x2 = c(0.258, -0.030, 0.071, 0.315, 0.223)
)

link_to_img <- function(x, width = 30) {
  glue::glue("<img src='{x}' width='{width}'/>")
}

plot <- data %>%
  mutate(label = link_to_img(label)) %>%
  ggplot() +
  geom_dumbbell(aes(x = x1, xend = x2, y = label)) +
  theme(axis.text.y = element_markdown())

plot
Ben_89
  • 249
  • 1
  • 8
  • What is the error that it returns? That would be useful information to share. – Jon Spring Aug 16 '21 at 03:36
  • Thanks, @JonSpring. I've included the returned error in my original post. – Ben_89 Aug 16 '21 at 04:10
  • Works fine on my machine except for a warning `In png::readPNG(get_file(path), native = TRUE): libpng warning: iCCP: known incorrect sRGB profile` – stefan Aug 16 '21 at 10:05

0 Answers0