Defining a function and plotting a function are two related but different topics, since Nir is already addressing the first part here I suggest you open a new topic for the second one providing a REPRoducible EXample (reprex).
About the first part, here you can find a nice introduction to functions in R