簡體   English   中英

將徽標嵌入在另一個嵌入式徽標的頂部

[英]Embed logo on top of another embedded logo in plotly

我有一個我想在溜冰場上繪制的曲棍球射擊位置的示例數據集( 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))

我成功地將溜冰場和我先前問題的答案結合在一起。 現在,我想嵌入兩個徽標(主隊/離隊徽標),並且我嘗試了此代碼,但無濟於事...

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等,但是我不知道這些參數是什么意思

我認為您的第二張圖片可能有問題(太大,太小?)。 例如,使用網絡上的另一張圖片(在此處拍攝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坐標)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM