watermark

345 views
Skip to first unread message

Jonas Tundo

unread,
May 21, 2012, 9:38:05 AM5/21/12
to ggp...@googlegroups.com

Hello,

 

Is there an easy way to add a watermark to a ggplot? At the moment I use annotate() with a low alpha value. For example:

annotate("text", x=0.5 , y = 80,label="Test watermark", size=4, alpha=0.5)

 

Does somebody know a better solution?

 

Greetings,

Jonas

 

 

 

Dennis Murphy

unread,
May 21, 2012, 8:38:28 PM5/21/12
to Jonas Tundo, ggp...@googlegroups.com
Hi:

I don't have any direct experience with this sort of thing, but you
should be able to use something like annotation_raster() or
annotation_custom() [both new in ggplot2-0.9.0] as an initial
background layer if your watermark is a graphic. However, neither
function seems to have the option to set alpha transparency for the
input graphic, so you'd need to do that in advance. Whether this is
'better' than your approach is for you to decide - if your actual
watermark is a text string, then I see no reason to deviate from your
current method.

If you have a solid graphical object that you want for a background,
one way to fake transparency, I guess, would be to use one of the
above as the first layer in the ggplot2 graph, and then overlay it
with a geom_rect() at full size in a solid color with alpha
transparency before adding anything else. You could write a function
to do that.

A couple of examples of the use of the aforementioned annotation
functions are in the ggplot2-0.9.0 transition guide, section 4:
http://cloud.github.com/downloads/hadley/ggplot2/guide-col.pdf

HTH,
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

baptiste auguie

unread,
May 21, 2012, 9:17:02 PM5/21/12
to Dennis Murphy, Jonas Tundo, ggp...@googlegroups.com
This sounds like a good theme for a blog post on tumblr. Do you have
specific requirements for what the watermark should look like?
(graphic/text, transparency, location, size, ...)

Cheers,

b.

Jonas Tundo

unread,
May 22, 2012, 3:45:33 AM5/22/12
to baptiste auguie, Dennis Murphy, ggp...@googlegroups.com
Indeed. In the example I used text at a fixed location, but in most cases a logo across the plot is preferable.
I do not have specific requirements at the moment, it would be interesting to play with all the parameters that you mention. Other parameters that come to my mind are angle, number of repeats/watermarks, colour.
It is very important that the watermark doesn't distort the plot too much, the interpretation of the plot may not change/become more difficult.

Thanks,
Jonas

-----Oorspronkelijk bericht-----
Van: baptiste auguie [mailto:baptist...@googlemail.com]
Verzonden: dinsdag 22 mei 2012 3:17
Aan: Dennis Murphy
CC: Jonas Tundo; ggp...@googlegroups.com
Onderwerp: Re: watermark

baptiste auguie

unread,
May 22, 2012, 5:57:50 AM5/22/12
to Jonas Tundo, Dennis Murphy, ggp...@googlegroups.com
I've now blogged about this,

http://ggplot2.tumblr.com/

b.

Jonas Tundo

unread,
May 22, 2012, 7:24:43 AM5/22/12
to baptiste auguie, Dennis Murphy, ggp...@googlegroups.com
Thanks. I like the examples.

Jonas

-----Oorspronkelijk bericht-----
Van: baptiste auguie [mailto:baptist...@googlemail.com]
Verzonden: dinsdag 22 mei 2012 11:58
Aan: Jonas Tundo
CC: Dennis Murphy; ggp...@googlegroups.com
Onderwerp: Re: watermark
Reply all
Reply to author
Forward
0 new messages