Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

r - Watermark in rmarkdown

I have researched and found how to create a watermark in an rmarkdown document.

It works great on basic text, but when you have a plot heavy page, it gets hidden behind the plot.

Obviously, this makes it easy for someone to screencap the figures and use them outside of the PDF.

Below is some code that demonstrates the issue clearly.

---
title: "Testing Watermark"
author: "John"
date: "September 18, 2015"
header-includes:
   - usepackage{draftwatermark}
output:
  pdf_document
---

This is some basic text.  
Note the watermark on this page, and the hidden watermark on the next page.


ewpage

SetWatermarkText{DRAFT}

```{r echo=FALSE, warning=FALSE, message=FALSE, fig.height=7}
library(ggplot2)

ggplot(mtcars) +
  geom_point(aes(mtcars$mpg, mtcars$cyl)) +
  facet_wrap(~carb, ncol=1) + 
  theme_bw()
```

If anyone is aware of a fix for this, I'd be grateful.

Either making the ggplot backgrounds transparent (which I've tried), or bringing the watermark to the foreground and making it transparent would be ok as far as I'm concerned.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using

header-includes:
   - usepackage{eso-pic,graphicx,transparent}

and then on the first page of your document (within the LaTeX part), add

AddToShipoutPictureFG{
  AtPageCenter{% or AtTextCenter
    makebox[0pt]{
otatebox[origin=c]{45}{%
      scalebox{5}{exttransparent{0.3}{DRAFT}}%
    }}
  }
}

This should add a rotated DRAFT message (semi-transparent) in the ForeGround (over top) of the page.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...