import libaries required
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
here we create a function Labeling, namingand the linetypes for the graph is done in below code lines
plot_math_curves<-function(exprs,range,line_types)
{
curves<-data.frame(x=seq(range[1],range[2],length.out=100))
curve_data<-lapply(seq_along(exprs),function(i){
curves%>%
mutate(
y=eval(parse(text=exprs[i])),
group=paste("group",i),
line_type=line_types[i]
)
}) %>% bind_rows()
ggplot(curve_data,aes(x=x,y=y,group=group,color=group,linetype=line_type))+
geom_line(size=1)+
labs(
tittle="plot of mathematical curves",
x="x",
y="y"
)+
theme_minimal()+
scale_color_brewer(palette = "Dark2")+
scale_linetype_manual(values=unique(curve_data$line_type))
}
here are few examples where mathematical equations are given as input displaying of the plots for the given equations
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.