【发布时间】:2016-10-23 15:15:43
【问题描述】:
我尝试使用“plotly”R 包在 R 图形中绘制图像。
我首先尝试包含来自本地计算机的图像:
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"
)
)
)
但我没能做到。然后我认为这是因为 plotly 显然需要 http 或 https 图像。
第一个问题:是否可以从本地文件导入图像(显然可以使用 python:https://plot.ly/python/images/)?
由于似乎无法嵌入本地图像,因此我尝试导入已在 Github 上上传的图像。但它似乎也不起作用:
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"
)
)
)
这里有什么问题?
我到处寻找,在 plotly 论坛(http://community.plot.ly/t/import-a-local-image-in-plot/2476,http://community.plot.ly/t/add-a-background-image/2457)上发布了问题,但我没有找到答案。
你有什么想法吗?
【问题讨论】:
-
你看到了吗plot.ly/~as5165/12/#code。不是 R,但可能会有所帮助。图片是base64。让我们知道您的进展情况