How to overlay and position a logo over any R plot (igraph, ggplot2, etc) so I can put branding on it automatically?

六月ゝ 毕业季﹏ 提交于 2019-12-01 14:27:10

if you are looking for an easy solution, the simplest way to do it would be to overlay your plot with a custom background:

require(ggplot2); require(grid); require(png);
data(mtcars)
# read background image, stacks website logo in this case
img <- readPNG(source = "so.png")
# add rater      
g <- rasterGrob(img, interpolate=TRUE) 
# Basic plot
ggplot(mtcars, aes(wt, mpg)) +
    geom_point() +
    annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)

The code would produce the following result:

Naturally, you can adjust your background by changing the image and placement to make it look more like a proper logo if you wish.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!