I am trying to annotate a plot by including custom images as the labels for a discrete x axis.
I have used the package ggtext
which adds this functionality to ggplot, and while I am able to replicate the example provided in the documentation of ggtext fior the iris
datase, as son as i stat using custom images, either from a link or reading them from file i stat getting errors which i cannot seems to solve. I have tried converting the image to different formats still no success.
here is an example with my custom images
labels <- c(
setosa = "<img src='https://github.com/hcuve/halo_faces/blob/main/ggtextimgs/comp1.JPG'
width='100' /><br>*I. *",
virginica = "<img src='https://github.com/hcuve/halo_faces/blob/main/ggtextimgs/comp2.JPG'
width='100' /><br>*I. *",
versicolor = "<img src='https://github.com/hcuve/halo_faces/blob/main/ggtextimgs/comp3.JPG'
width='100' /><br>*I. *"
)
ggplot(iris, aes(Species, Sepal.Width)) +
geom_boxplot() +
scale_x_discrete(
name = NULL,
labels = labels
) +
theme(
axis.text.x = element_markdown(color = "black", size = 11)
)
this throws the following error: Error in jpeg::readJPEG(get_file(path), native = TRUE) : JPEG decompression error: Not a JPEG file: starts with 0x0a 0x0a