Adding a caption to a plot

To add caption we will use caption attributes from labs() function.

Syntax: labs(caption)

Parameters: 

  • caption: String caption

R




library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
    geom_point()+
  
    # adding caption and subtitle
    labs(subtitle="Scatter plot",
       caption="w3wiki"
       )


Output:

How to Add Caption to a ggplot in R?

In this article, we are going to see how we can add a caption to a plot in R Programming Language. The caption is much important in data visualization to display some details related to graphs.

Similar Reads

Preparing Data

To plot the scatterplot we will use we will be using the geom_point() function. Following is brief information about the ggplot function, geom_point()....

Adding a caption to a plot

...

Customize caption text

To add caption we will use caption attributes from labs() function....