title: “program7” author: “jaishree-int23is088” format: html editor: visual —

program 7

develop a function in R to plot a function curve based on a mathematical equation provided as input,with different curve styles for each group using ggpolt2

step1:load the package

library(ggplot2)

step2;create data for the functions

x<-seq(-2*pi,2*pi,length.out=500)

y1<-sin(x)
y2<-cos(x)

df <- data.frame(
  x = rep(x, 2),
  y = c(y1, y2),
  group = rep(c("sin(x)", "cos(x)"), each = length(x))
)

step 3.1:initialize the ggplot object

p <-ggplot(df,aes(x=x,y=y,color=group,linetype = group))
p

step 3.2:add the line geometry

p <- p + geom_line(linewidth = 1.2)

step 3.3:add plot labels

p<-p+labs(title = "Function curves:sin(x) and cos(x)",
          x="x",
          y="y=f(x)",
          color="Function",
          linetype="Function")
p

step 3.4:apply a clean theme

p<-p+theme_minimal()
p