簡體   English   中英

將透明標志插入 ggplot2 背景

[英]Inserting a transparent logo to the ggplot2 background

我想在 ggplot 背景中添加一個透明的圖像\\標志。

我嘗試了以下方法。

 m <- readPNG(".\\Input\\Logo.png", FALSE)

 w <- matrix(rgb(m[,,1],m[,,2],m[,,3], m[,,4] * 0.2), nrow=dim(m)[1])

 qplot(1:10, rnorm(10), geom = "blank") +
 annotation_custom(xmin=-Inf, ymin=-Inf, xmax=Inf, ymax=Inf,    
 rasterGrob(w)) + geom_point()

但我收到一個錯誤: m[, , 4] 中的錯誤:下標越界。

感謝您對此的支持。

我沒有.\\\\Input\\\\Logo.png但是,請嘗試以下操作:

library(png)
m <- readPNG(system.file("img", "Rlogo.png", package="png"))
w <- matrix(rgb(m[,,1],m[,,2],m[,,3], m[,,4] * 0.2), nrow=dim(m)[1])
qplot(1:10, rnorm(10), geom = "blank") +
  annotation_custom(xmin=-Inf, ymin=-Inf, xmax=Inf, ymax=Inf,    
                    rasterGrob(w)) + geom_point()

根據該評論@lukeA的w <- abind::abind(m, matrix(0.2, ncol = ncol(m[,,3]), nrow = nrow(m[,,3]))) - 0.2工作了我。

暫無
暫無

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

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