簡體   English   中英

R Plotly 添加圖片水印

[英]R Plotly add image watermark

我想將圖像/水印添加到雙 y 軸 plot,不知何故我的代碼不起作用.....這怎么可能? 它沒有錯誤,但沒有添加圖像

df <- data.frame(x = 1:50,
                 y1 = c(20:5,6:10,9:3,4:20, 19:15),
                 y2 = c(100:115,200:204,50:44,4:20, 66:62))

還有我的代碼

plot_ly(df) %>% 
  add_lines(type = 'scatter', mode = "lines", 
            name = "test", 
            x = ~x, y = ~y1,
            line = list(color = '#999999'),
            hoverinfo = "text",
            text = ~paste(round(y1, 1), x))  %>%
  add_lines(type = 'scatter', mode = "lines", 
            name = "test", yaxis = 'y2',
            x = ~x, y = ~y2,
            line = list(color = '#CC79A7'),
            hoverinfo = "text",
            text = ~paste(round(y2, 1), x)) %>%
  #layout
  layout(title = "test",
         xaxis = list(titel = "Date", 
                      rangeslider = list(thickness = 0.05)),
         yaxis = list(side = 'left', title = 'test', 
                      showgrid = F, zeroline = F, type = "log",
                      showline = T),
         images = list(source = "https://rstudio.com/wp-content/uploads/2018/10/RStudio-Logo.png",
                       xref = "paper",
                       yref = "paper",
                       xanchor = "left", 
                       yanchor = "bottom",
                       x= 4,
                       y=4,
                       sizex = 5,
                       sizey = 5,
                       opacity = 0.8),
         yaxis2 = list(side = 'right', overlaying = "y", 
                       title = 'test', 
                       showgrid = F, zeroline = F, 
                       showline = T))

在此處輸入圖像描述

問題是您無權訪問 Rstduio-logo.png。

  1. 創建一個 www 文件夾
  2. 將 a.png 放在這個 www 文件夾中,假設我稱之為 test.png
  3. 然后簡單地說:

layout(images = list(source = "test.png"))

暫無
暫無

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

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