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 13:52:40

问题


I am wondering if there is a generic way to overlay any R plot / visualization appearing in the R output window with a logo (as well as position it) so output is always branded?

I read this post where they use a stripe banner as part of ggplot, but is there more of a generic way of doing this so I can include it in any output to automatically put the appropriate branding in particular location (realizing it will likely have to be adjusted, but at least so it is always there) so I cna have it be part of say the 'default code template' so whether I or my colleague use generic plot, igraph, ggplot2, or any other graphics package it always will always get overlayed?


回答1:


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.

来源:https://stackoverflow.com/questions/30152309/how-to-overlay-and-position-a-logo-over-any-r-plot-igraph-ggplot2-etc-so-i-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!