Annotate Multiple Lines of Text to ggplot2 Plot in R Last Updated : 07 Jul, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will see how to annotate Multiple Lines of text to ggplot2 Plot in R programming language. Let us first create a regular plot so that the difference is apparent, Example: R # Load Package library("ggplot2") # Create a DataFrame DF <- data.frame(X = runif(100, min=0, max=100), Y = runif(100, min=0, max=100)) # Create a ScatterPlot using ggplot2. ggplot(DF,aes(X, Y))+ geom_point(size = 5, fill = "green", color = "black", shape = 21) Output: ScatterPlot using ggplot2 Now to annotate multiple lines to the plot annotate() function is used along the regular plot. This function is passed the required value and attributes. The approach is similar to adding a single line to the plot, only difference being each new line should be created by using "\n" within the text that is to be passed to the plot. Syntax : annotate(geom, x, y, label) Parameters : geom : We assign geom that we want to add to the plot as a first parameter which will written in "" . geom can be anything like rect, segment, pointrange etc. here we will use text as a geom as we want to add text. all other arguments will be depends on geom that we select. So here all other parameters that we will use are only works for Annotating text to plot.x : Represents the Co-ordinates of X Axis.y : Represents the Co-ordinates of Y Axis.label : Text that we want to annotate on plot.Above threes parameters (i.e x, y and label) are necessary for annotating text but here we will also use two parameters size and color which are used to represent size and color of text respectively and they are not necessary to use. Return : Geoms on plot. Example: R # Load ggplot2 Package library("ggplot2") # Create a DataFrame for Plotting DF <- data.frame(X = runif(100, min=0, max=100), Y = runif(100, min=0, max=100)) # ScatterPlot with Multiple Lines Text on it. ggplot(DF,aes(X, Y))+ geom_point(size = 5, fill = "green", color = "black", shape = 21)+ annotate("text", x = 50, y = 10, label = "Geeks For Geeks\n(R Tutorial)", size = 10, color = "dark green") Output: ScatterPlot with Annotating Multiple Lines on Plot Comment More infoAdvertise with us Next Article Annotate Text Outside of ggplot2 Plot in R E erkrutikpatel Follow Improve Article Tags : R Language R-ggplot Similar Reads Annotate Text Outside of ggplot2 Plot in R Ggplot2 is based on the grammar of graphics, the idea that you can build every graph from the same few components: a data set, a set of geomsâvisual marks that represent data points, and a coordinate system. There are many scenarios where we need to annotate outside the plot area or specific area as 2 min read How to create a plot using ggplot2 with Multiple Lines in R ? In this article, we will discuss how to create a plot using ggplot2 with multiple lines in the R programming language. Method 1: Using geom_line() function In this approach to create a ggplot with multiple lines, the user need to first install and import the ggplot2 package in the R console and then 3 min read How to annotate a plot in ggplot2 in R ? In this article, we will discuss how to annotate functions in R Programming Language in ggplot2 and also read the use cases of annotate. What is annotate?An annotate function in R can help the readability of a plot. It allows adding text to a plot or highlighting a specific portion of the curve. Th 4 min read How to Combine Multiple ggplot2 Plots in R? In this article, we will discuss how to combine multiple ggplot2 plots in the R programming language. Combining multiple ggplot2 plots using '+' sign to the final plot In this method to combine multiple plots, here the user can add different types of plots or plots with different data to a single p 2 min read How to rotate only text in annotation in ggplot2? R has ggplot2 which is a data visualization package for the statistical programming language R. After analyzing and plotting graphs, we can add an annotation in our graph by annotate() function. Syntax: annotate() Parameters: geom : specify textx : x axis locationy : y axis locationlabel : custom te 2 min read How to put text on different lines to ggplot2 plot in R? ggplot2 is a plotting package in R programming language that is used to create complex plots from data specified in a data frame. It provides a more programmatic interface for specifying which variables to plot onto the graphical device, how they are displayed, and general visual properties. In thi 3 min read Like