wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
651 stars 37 forks source link

Error when using web images as axis labels #65

Closed aappiah17 closed 3 years ago

aappiah17 commented 3 years ago

I get the following error when trying use to use web images as axis labels: Error in function (type, msg, asError = TRUE) : error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version.

Even trying to reproduce the example in the package documentation produces the same error

library(tidyverse)
library(ggtext)

labels <- c(
  setosa = "<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Iris_setosa.JPG/180px-Iris_setosa.JPG'
    width='100' /><br>*I. setosa*",
  virginica = "<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Iris_virginica_-_NRCS.jpg/320px-Iris_virginica_-_NRCS.jpg'
    width='100' /><br>*I. virginica*",
  versicolor = "<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/20140427Iris_versicolor1.jpg/320px-20140427Iris_versicolor1.jpg'
    width='100' /><br>*I. versicolor*"
)

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)
  )
#> Error in function (type, msg, asError = TRUE) : error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
clauswilke commented 3 years ago

It's unlikely that it's a ggtext issue. Does this work for you?

magick::image_read("https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/20140427Iris_versicolor1.jpg/320px-20140427Iris_versicolor1.jpg")

Created on 2021-05-12 by the reprex package (v1.0.0)

aappiah17 commented 3 years ago

Yes, it works. I use magick and ggimage usually with web links and they work fine. I was trying to use images as axis labels

clauswilke commented 3 years ago

Sorry, I was confused. I'm not actually using magick, I'm using jpeg::readJPEG(): https://github.com/wilkelab/gridtext/blob/master/R/read-image.R

So, does the following work for you?

img <- jpeg::readJPEG(RCurl::getBinaryURL("https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/20140427Iris_versicolor1.jpg/320px-20140427Iris_versicolor1.jpg"))

grid::grid.raster(img)

Created on 2021-05-12 by the reprex package (v1.0.0)

aappiah17 commented 3 years ago

I get that error again.

img <- jpeg::readJPEG(RCurl::getBinaryURL("https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/20140427Iris_versicolor1.jpg/320px-20140427Iris_versicolor1.jpg"))
#> Error in function (type, msg, asError = TRUE) : error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Created on 2021-05-12 by the reprex package (v1.0.0)
clauswilke commented 3 years ago

Yeah, so it's probably an issue with RCurl. Maybe an installation problem? Definitely not a ggtext issue, since that latest example doesn't use any ggtext functions.

clauswilke commented 3 years ago

Maybe this explains it: https://twitter.com/opencpu/status/1131264122203492352?s=20

If you want to prepare a PR to gridtext (https://github.com/wilkelab/gridtext/) replacing RCurl with curl I'll welcome it.

aappiah17 commented 3 years ago

Thanks. Will prepare a PR.