Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...