library(ggplot2)
—
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
step2;create data for the functions
<-seq(-2*pi,2*pi,length.out=500)
x
<-sin(x)
y1<-cos(x)
y2
<- data.frame(
df 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
<-ggplot(df,aes(x=x,y=y,color=group,linetype = group))
p p
step 3.2:add the line geometry
<- p + geom_line(linewidth = 1.2) p
step 3.3:add plot labels
<-p+labs(title = "Function curves:sin(x) and cos(x)",
px="x",
y="y=f(x)",
color="Function",
linetype="Function")
p
step 3.4:apply a clean theme
<-p+theme_minimal()
p p