I try to use the "plotly" R package to plot an image in an R graphic.
I first tried to include an image from a local computer:
library(plotly)
outfile <- tempfile(fileext = ".png")
png(outfile)
plot(rnorm(200), rnorm(200))
dev.off()
plot_ly(x = c(1, 2, 3), y = c(1, 2, 3)) %>%
layout(
images = list(
list(
source = outfile,
xref = "x",
yref = "y",
x = 1,
y = 1,
sizex = 2,
sizey = 2,
sizing = "stretch",
opacity = 0.4,
layer = "below"
)
)
)
But I did not manage to do it. I then thought that was because plotly apparently requires an http or https image.
First question: Is it possible to import image from a local file (apparently it is possible with python: https://plot.ly/python/images/)?
As it seems to be impossible to embed a local image, I try to import an image that I had upload on my Github. But it seems not to work neither:
library(plotly)
plot_ly(x = c(1, 2, 3), y = c(1, 2, 3)) %>%
layout(
images = list(
list(
source = "https://github.com/charlottesirot/elementR/blob/master/inst/www/2.png",
xref = "x",
yref = "y",
x = 1,
y = 1,
sizex = 2,
sizey = 2,
sizing = "stretch",
opacity = 0.4,
layer = "below"
)
)
)
What is the problem here?
I have looked everywhere, posted questions on plotly forum (http://community.plot.ly/t/import-a-local-image-in-plot/2476, http://community.plot.ly/t/add-a-background-image/2457) but I did not find my answers.
Do you have any idea?