• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to add water mark on a ggplot

datavizpyr · May 20, 2022 ·

In this tutorial, we will learn how to add water marks to a plot made in R. We will use ggplot2 to make the plot and use the R package cowplot to add water mark on top the plot.

The cowplot package developed by Claus Wilke

functions to draw with and on plots. These functions enable us to take plots and add arbitrary annotations or backgrounds, to place plots inside of other plots, to arrange plots in more complicated layouts, or to combine plots from different graphic systems (ggplot2, grid, lattice, base). This functionality is build on top of ggplot2, i.e., the resulting plots are ggplot2 objects and they can be modified, extended, and outputted just like regular ggplot2 plots.

In case if you wonder about the package name,

The package was originally written for internal use in the Wilke lab, hence the name (Claus O. Wilke’s plot package). It has also been used extensively in the book Fundamentals of Data Visualization.

Let us get started by loading the R packages needed to make a plot with watermark.

library(tidyverse)
library(palmerpenguins)
library(cowplot)

We use palmer penguins dataset to make a simple scatter plot with ggplot.

p <- penguins %>%
  ggplot(aes(x = flipper_length_mm,
             y = body_mass_g,
             color = species))+
  geom_point()+
  labs(title= "How to add watermark on a plot",
       caption="cmdlinetips.com")+
  theme_bw(16)
print(p)
ggsave("simple_scatterplot_with_ggplot2.png")

Simple Scatter Plot with ggplot2
Simple Scatter Plot with ggplot2

And we want to add water mark label on top of the scatterplot. The R package cowplot offers multiple functions to add annotation on top of the plot.

A key function from cowplot to add annotation is ggdraw() and we apply this function on the ggplot object and then use draw_label() to add the water mark on top of the plot. We can customize the text, color, size and the angle of watermark using the arguments shown below.

ggdraw(p) +
  draw_label("Draft", 
             color = "lightgray",
             size = 100, 
             angle = 45)
ggsave("how_to_add_watermark_on_ggplot2_using_cowplot.png")

And we get this nice plot with watermark on it.

How to add water mark to a plot in R
How to add water mark to a plot in R

Thanks to the fantastic documentation of cowplot package, instead of using the draw_label() function to add water mark to a plot we can use ggplot2 function geom_text() as shown below.

ggdraw(p) +
 geom_text(
    data = data.frame(x = 0.5,
                      y = 0.5, label = "Draft"),
    aes(x, y, label = label),
    hjust = 0.5, vjust = 0.5, angle = 45, size = 100/.pt,
    color = "lightgray",
    inherit.aes = FALSE
  )
ggsave("how_to_add_watermark_on_ggplot2_using_geom_text.png")
How to add water mark to a plot made with ggplot2
How to add water mark to a plot made with ggplot2

Related posts:

Customizing Mean mark to boxplot with ggplot2How To Show Mean Value in Boxplots with ggplot2? Scatterplot with marginal multi-histogram with ggExtraHow To Make Scatterplot with Marginal Histograms in R? ggforce geom_circle(): Annotate with a circleHow To Annotate a Plot with Circle in R Default ThumbnailHow to Make Axis Text Bold in ggplot2

Filed Under: ggplot2, R Tagged With: add water mark ggplot2

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version