Search code examples
rfunctionplotparametric-equations

Plot two functions in one plot in rstudio


I have two functions

fun1 <- function(x) -(2 * (sin(x) * cos(x)))
fun2 <- function(x) 2 * (cos(x) * sin(x))

I want to plot them both in one diagram. I have the parametrization

\gamma (x) =(-2*sin(x)*cos(x),2*cos(x)*sin(x))

And actually if it was possible I want ONE function (ex.fun3) where both is defined and then plot fun3 instead of defining one for each. Can someone help me with both questions?

Regards,

s


Solution

  • check here 
    

    https://rpubs.com/kaz_yos/ggplot2-stat-function

    fun1 <- function(x) {-(2 * (sin(x) * cos(x)))}
        fun2 <- function(x) {(2 * cos(x) * sin(x))}
        ggplot(data=data.frame(0)) + stat_function(fun = fun1) + stat_function(fun = fun2)+xlim(-3,3)