如何在任何R图(igraph,ggplot2等)上叠加和定位徽标,以便我可以将徽标自动加入? [英] How to overlay and position a logo over any R plot (igraph, ggplot2, etc) so I can put branding on it automatically?

查看:358
本文介绍了如何在任何R图(igraph,ggplot2等)上叠加和定位徽标,以便我可以将徽标自动加入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种通用的方式来覆盖出现在R输出窗口中带有徽标(以及位置)的R绘图/可视化,因此输出总是被打上标记?



我阅读了此文章他们在哪里使用条纹横幅作为ggplot的一部分,但是有更多的通用方法来做到这一点,所以我可以将它包含在任何输出中,以自动在特定位置放置适当的品牌(意识到它可能不得不但至少它总是在那里),所以我认为它是'默认代​​码模板'的一部分,所以无论是我还是我的同事使用通用绘图,igraph,ggplot2或任何其他图形包,它总是会始终重叠?

解决方案

如果您正在寻找一个简单的解决方案,最简单的方法就是用自定义背景:

  require(ggplot2);要求(网格);要求(PNG); 
data(mtcars)
#读取背景图片,在这种情况下堆叠网站标志
img< - readPNG(source =so.png)
#add rater
g < - rasterGrob(img,interpolate = TRUE)
#基本图
ggplot(mtcars,aes(wt,mpg))+
geom_point()+
annotation_custom( g,xmin = -Inf,xmax = Inf,ymin = -Inf,ymax = Inf)

代码会产生以下结果:

当然,您可以调整背景通过改变图像和位置,使其看起来更像一个适当的标志,如果你愿意。

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?

解决方案

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.

这篇关于如何在任何R图(igraph,ggplot2等)上叠加和定位徽标,以便我可以将徽标自动加入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆