Search code examples
rggplot2plotlatticer-faq

How to plot a function curve in R


What are the alternatives for drawing a simple curve for a function like

eq = function(x){x*x}

in R?

It sounds such an obvious question, but I could only find these related questions on stackoverflow, but they are all more specific

I hope I didn't write a duplicate question.


Solution

  • You mean like this?

    > eq = function(x){x*x}
    > plot(eq(1:1000), type='l')
    

    Plot of eq over range 1:1000

    (Or whatever range of values is relevant to your function)