Draw Multiple Function Curves to Same Plot in R Last Updated : 15 Feb, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to plot multiple function curves to the same plot in the R programming language. Method 1: In Base R Base R supports a function curve() which can be used to visualize a required function curve. It supports various parameters to edit the curve according to requirements. Syntax: curve(expression, to, from, col) Parameters: expression: To be curvedto, from: range of curve plottingcol: color of curve To draw multiple curves in one plot, different functions are created separately and the curve() function is called repeatedly for each curve function. The call for every other curve() function except for the first one should have added an attribute set to TRUE so that multiple curves can be added to the same plot. To differentiate among the different colors are used. Example: R function1<- function(x){x ** 2} function2<-function(x){x ** 3} function3<-function(x){x / 2} function4<-function(x){2*(x ** 3)+(x ** 2)-(x / 2)} curve(function1, col = 1) curve(function2, col = 2, add = TRUE) curve(function3, col = 3, add = TRUE) curve(function4, col = 4, add = TRUE) Output: Method 2: Using ggplot GGPLOT2 is an R library used to visualize plots with its various easy-to-use functions. To draw multiple curves using ggplot functions are first created normally. But to draw them in the same plot, the functions are converted to dataframe and then visualized. Example: R library("ggplot2") function1<- function(x){x ** 2} function2<-function(x){x ** 3} function3<-function(x){x / 2} function4<-function(x){2*(x ** 3)+(x ** 2)-(x / 2)} df=data.frame(x = -2 : 2, values = c(function1(-2 : 2), function2(-2 : 2), function3(-2 : 2), function4(-2 : 2)), fun = rep(c("function1", "function2", "function3", "function4")) ) ggplot(df, aes(x, values, col = fun))+geom_line() Output: Comment More infoAdvertise with us Next Article Draw Multiple Function Curves to Same Plot in R V vanshikagoyal43 Follow Improve Article Tags : R Language R-plots R-Charts R-Graphs R-ggplot +1 More Similar Reads Draw Multiple Time Series in Same Plot in R Time Series in R programming language is used to see how an object behaves over a period of time. In R, it can be easily done by the ts() function with some parameters. Time series takes the data vector and each data is connected with timestamp value as given by the user. Method 1: Using Basic R me 2 min read Draw Multiple Graphs and Lines in Same Plot in R A visualization can sometimes make more sense when multiple graphs and line plots are combined into one plot. In this article, we will discuss how we can do the same in the R programming language. Method 1: Using base R Base R supports certain methods that can be used to generate the desired plot. I 3 min read How to create a reusable plot_ly function in R In data visualization, reusability and consistency are crucial for maintaining clarity and efficiency. Plotly is the powerful library in the R for creating interactive plots. By encapsulating the plotting logic into the reusable functions. We can streamline the plotting process and it can ensure uni 5 min read Fit Smooth Curve to Plot of Data in R In this article, we will learn about the concept to fit a smooth curve to the plot of data in R Programming. Smoothing is an important concept in data analysis. It is also known as curve fitting and low pass filtering. The most common non-parametric method used for smoothing is loess() function. Loe 3 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 Like