How can I add a footnote to my ggplot2 plot? 2

How can I add a footnote to my ggplot2 plot?

Adding a footnote to a ggplot2 plot allows for the inclusion of additional information or references related to the data being presented. This can be achieved by using the “annotate” function and specifying the “text” argument, followed by the footnote text and the desired location for the footnote on the plot. By adding a footnote, the plot becomes more informative and provides context for the data being visualized.

Add Footnote to ggplot2 Plots


You can use the caption argument within the labs() function to add a footnote to a plot in ggplot2.

There are two common ways to use this argument in practice:

Method 1: Add Footnote in Bottom Right Corner

p +
  labs(caption = "Here is a footnote")

Method 2: Add Footnote in Bottom Left Corner

p +
  labs(caption = "Here is a footnote") +
  theme(plot.caption = element_text(hjust=0))

The following examples show how to use each method in practice with the following data frame in R:

#create data frame
df <- data.frame(assists=c(1, 2, 2, 3, 5, 6, 7, 8, 8),
                 points=c(3, 6, 9, 14, 20, 23, 16, 19, 26))

#view data frame
df

  assists points
1       1      3
2       2      6
3       2      9
4       3     14
5       5     20
6       6     23
7       7     16
8       8     19
9       8     26

Example 1: Add Footnote in Bottom Right Corner

The following code shows how to create a scatter plot in gglot2 and add a footnote in the bottom right corner below the plot:

library(ggplot2)

#create scatter plot with footnote in bottom right corner
ggplot(df, aes(x=assists, y=points)) +
  geom_point(size=3) +
  labs(caption = "Here is a footnote")

ggplot2 add footnote

Notice that a footnote has been added to the bottom right corner below the plot.

Example 2: Add Footnote in Bottom Left Corner

The following code shows how to create a scatter plot in gglot2 and add a footnote in the bottom left corner below the plot:

library(ggplot2)

#create scatter plot with footnote in bottom left corner
ggplot(df, aes(x=assists, y=points)) +
  geom_point(size=3) +
  labs(caption = "Here is a footnote") +
  theme(plot.caption = element_text(hjust=0))

ggplot2 add footnote in bottom left corner

Note that the argument hjust=0 specifies that the footnote should be left-aligned.

You can also specify hjust=0.5 to place the footnote in the bottom center outside the plot.

The following tutorials explain how to perform other common tasks in ggplot2:

Cite this article

stats writer (2024). How can I add a footnote to my ggplot2 plot?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-add-a-footnote-to-my-ggplot2-plot/

stats writer. "How can I add a footnote to my ggplot2 plot?." PSYCHOLOGICAL SCALES, 25 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-add-a-footnote-to-my-ggplot2-plot/.

stats writer. "How can I add a footnote to my ggplot2 plot?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-add-a-footnote-to-my-ggplot2-plot/.

stats writer (2024) 'How can I add a footnote to my ggplot2 plot?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-add-a-footnote-to-my-ggplot2-plot/.

[1] stats writer, "How can I add a footnote to my ggplot2 plot?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I add a footnote to my ggplot2 plot?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top