Adding a watermark to your plots
library(ggplot2)
library(grid)
qplot(1:10, rnorm(10)) +
annotate("text", x = Inf, y = 0, label = "@Amit Kumar Garg 2015", hjust=1.1, vjust=-1.1, col="white", cex=6, fontface = "bold", alpha = 0.8)
qplot(1:10, rnorm(10)) +
annotate("text", x = Inf, y = 0, label = "@Amit Kumar Garg 2015",vjust=-1, col="white", cex=6, fontface = "bold", alpha = 0.8,srt = 90)
Adding a plot as watermark on your main plot
base <- qplot(1:10, 1:10, geom = "blank") + theme_bw()
g <- ggplotGrob(qplot(1, 1) +
theme(plot.background = element_rect(colour = "black")))
base +
annotation_custom(grob = g, xmin = 1, xmax = 10, ymin = 8, ymax = 10)
#Inf,-Inf
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.
run.date <- format(Sys.Date(), "%m-%d-%Y")
#png(paste0("Watermark 1 - ", run.date, ".png"))
plot(rnorm(100))
text(x = grconvertX(0.5, from = "npc"), # align to center of plot X axis
y = grconvertY(0.5, from = "npc"), # align to center of plot Y axis
labels = "CONFIDENTIAL", # our watermark
cex = 3, font = 2, # large, bold font - hard to miss
col = rgb(1, 0, 0, .2), # translucent (0.2 = 20%) red color
srt = 45) # srt = angle of text: 45 degree angle to X axis
# Add another watermark in lower (side = 1) right (adj = 1) corner
watermark <- paste("Data", run.date)
mtext(watermark, side = 1, line = -1, adj = 1, col = rgb(1, 0, 0, .2), cex = 1.2)
#dev.off() # close device, create image