【问题标题】:Embed logo on top of another embedded logo in plotly在情节中将徽标嵌入另一个嵌入徽标的顶部
【发布时间】:2019-02-17 21:01:16
【问题描述】:

我有这个示例数据集 (example_data),其中包含我想在溜冰场上绘制的曲棍球射击位置。

structure(list(game_date = structure(c(17674, 17674, 17674, 17674, 
17674), class = "Date"), event_team = c("WSH", "WSH", "T.B", 
"T.B", "T.B"), event_description = c("WSH #8 OVECHKIN(12), Slap, Off. Zone, 53 ft.Assists: #92 KUZNETSOV(13); #43 WILSON(8) Expected Goal Prob: 1.6%", 
"WSH ONGOAL - #92 KUZNETSOV, Wrist, Off. Zone, 13 ft. Expected Goal Prob: 50.4%", 
"T.B ONGOAL - #17 KILLORN, Backhand, Off. Zone, 18 ft. Expected Goal Prob: 4.5%", 
"T.B ONGOAL - #17 KILLORN, Wrist, Off. Zone, 23 ft. Expected Goal Prob: 4.6%", 
"T.B ONGOAL - #27 MCDONAGH, Slap, Off. Zone, 57 ft. Expected Goal Prob: 1.2%"
), event_type = c(1, 0, 0, 0, 0), home_team = c("T.B", "T.B", 
"T.B", "T.B", "T.B"), away_team = c("WSH", "WSH", "WSH", "WSH", 
"WSH"), coords_x = c(-42, -80.3, 71, 67, 34), coords_y = c(-21, 
12, -3, 9, 19)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-5L))

我成功地将溜冰场嵌入到我的previous question 的答案中。现在,我想嵌入两个徽标(主队/客队队徽),我试过这段代码无济于事......

example_data %>% 
  plot_ly(x = ~coords_x, y=~coords_y, 
          text= ~event_description)  %>%
  add_markers(size = ~event_type,
              sizes = c(150, 700),

              alpha = 0.75,
              color = ~factor(event_team),
              colors = c("black", "slategrey")
  ) %>%  
  layout(
    xaxis = list(range = c(-100,100)), 
    yaxis = list(range = c(-45,45)),
    images= list(
      list(
        source= "https://i.imgur.com/Y2kOUX5.png",
        xref= "paper",
        yref= "paper",
        x= 0,
        y= 1,
        sizex= 1,
        sizey= 1,
        opacity= 0.8,
        layer = "below"),
      list(
        source = "http://www.capsinfo.com/images/NHL_Team_Logos/NHL_Ducks_Primary.png"

      )
    )
  )

我做错了什么?我想我需要在列表中指定xrefyref 等,但我不知道这些参数是什么意思

【问题讨论】:

    标签: r r-plotly


    【解决方案1】:

    我认为您的第二张图片可能有问题(太大,太小?)。例如,使用来自网络的另一张图片(此处为https://community.plot.ly/t/plotly-unable-to-embed-a-logo-or-background-image-in-plotly/2100/18)作为您的第二个徽标,当您设置正确的参数时,您将看到第二个徽标出现。

    example_data %>% 
      plot_ly(x = ~coords_x, y=~coords_y, 
              text= ~event_description)  %>%
      add_markers(size = ~event_type,
                  sizes = c(150, 700),
    
                  alpha = 0.75,
                  color = ~factor(event_team),
                  colors = c("black", "slategrey")
      ) %>%  
      layout(
        xaxis = list(range = c(-100,100)), 
        yaxis = list(range = c(-45,45)),
        images= list(
          list(
            source= "https://i.imgur.com/Y2kOUX5.png",
            xref= "paper",
            yref= "paper",
            x= 0,
            y= 1,
            sizex= 1,
            sizey= 1,
            opacity= 0.8,
            layer = "below"),
          list(
            source = "https://images.contentful.com/w3cthbuv8rf8/1g2AFv1q32mcceWaSK6CCS/7e8ae1f1a9266a044aa1c7988612b985/2008-the-dark-knight-version-of-the-symbol-is-largely-unchanged-from-the-original.png",
            xref = "x",
            yref = "y",
            x = 50,
            y = -20,
            sizex = 20,
            sizey = 20,
            sizing = "stretch",
            opacity = 0.5
    
          )
        )
      )
    

    现在在你的问题中,你没有说你想把它放在哪里。要放置您的徽标,您可以使用两个不同的参考(纸张或 x/y 坐标)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 2020-05-03
      • 2021-03-10
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      相关资源
      最近更新 更多