Ich versuche, das "Plotly" R-Paket zu verwenden, um ein Bild in einer R-Grafik zu plotten.R plotly ein Bild im Hintergrund hinzufügen
Ich habe versucht, zuerst ein Bild von einem lokalen Computer enthalten:
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"
)
)
)
Aber ich schaffe nicht, es zu tun. Ich dachte das war, weil plotly anscheinend ein HTTP- oder HTTPS-Bild benötigt.
Erste Frage: Ist es möglich, Bild von einer lokalen Datei zu importieren (anscheinend ist es mit Python möglich: https://plot.ly/python/images/)?
Da es scheinbar unmöglich ist, ein lokales Bild einzubetten, versuche ich ein Bild zu importieren, das ich auf meinen Github hochgeladen habe. Aber es scheint auch nicht zu funktionieren:
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"
)
)
)
Was ist das Problem hier?
Ich habe überall gesucht, Fragen auf Plotly Forum (http://community.plot.ly/t/import-a-local-image-in-plot/2476, http://community.plot.ly/t/add-a-background-image/2457) gestellt, aber ich habe meine Antworten nicht gefunden.
Haben Sie eine Idee?
Haben Sie diesen https://plot.ly/~as5165/12/#code gesehen? Nicht R aber kann helfen. Bild ist base64. Lass uns wissen, wie es dir geht – pssguy