从图中R中的图像绘制散点图标记符号

时间:2018-02-05 11:26:23

标签: r image plotly r-plotly

我希望我的标记符号是文件中的图像,而不是列出here列出的默认符号。

我搜索但无法找到将图像文件用于符号的方法。 假设我有data.frame

dt<-data.frame(seq(1,10,by=1))

dt1<-data.frame(seq(1,20,by=1))

使用绘图:

plot_ly(dt, x=dt$seq.1..10..by...1., y=dt1$seq.1..20..by...1.) %>%
add_trace(dt, x = dt$seq.1..10..by...1., y = dt$seq.1..10..by...1., type = 'scatter', mode = 'markers',
marker = list(symbol=~2,size = 15, opacity = 0.5, colors="black"))

输出为: enter image description here

我可以在此处将symbol=的数字从~1更改为~32,但我想使用自定义图片。 任何关于如何做的想法。使用您想要的任何图像作为示例。

由于

1 个答案:

答案 0 :(得分:0)

You could probably adapt this:

plot_ly(dt, x=dt$seq.1..10..by...1., y=dt1$seq.1..20..by...1.) %>%
  add_trace(dt, x = dt$seq.1..10..by...1., y = dt$seq.1..10..by...1., type = 'scatter', mode = 'markers',
            marker = list(symbol=~2,size = 15, opacity = 0.5, colors="white")) %>%
  layout(
    images = list(
      list(source = "https://images.plot.ly/language-icons/api-home/python-logo.png",
           xref = "x",
           yref = "y",
           x= 1,
           y= 1,
           sizex = 0.2,
           sizey = 0.2,
           opacity = 0.8,
           layer = "above"
      ),

      list(source = "https://images.plot.ly/language-icons/api-home/matlab-logo.png",
           xref = "x",
           yref = "y",
           x = 2,
           y = 2,
           sizex = 0.5,
           sizey = 0.5,
           opacity = 0.8
      ),

      list(source =  "https://images.plot.ly/language-icons/api-home/r-logo.png",
           xref = "x",
           yref = "y",
           x = 2.5,
           y = 3.5,
           sizex = 1,
           sizey = 1,
           opacity = 0.8
      )
    )
  )