Book Image

R Graph Essentials

Book Image

R Graph Essentials

Overview of this book

This book is targeted at R programmers who want to learn the graphing capabilities of R. This book will presume that you have working knowledge of R.
Table of Contents (6 chapters)
5
Index

Graphing mathematical functions

Sometimes, you may wish to plot a mathematical function. We have already seen how to do that, but the curve() command provides a nice alternative. Let's plot a cubic curve using the curve() command. To use curve(), you must specify a function within the parentheses. Enter the following syntax:

curve(5*x**3 + 6*x**2 - 5, -2, 2 , col = "blue", main = "CUBIC CURVE")

The following is our graph:

Graphing mathematical functions

We have a smooth cubic curve and the axis limits we specified within the code. The curve() command allows you to specify a function as the first argument, the range of values over which you wish to create your graph, and add your graph to an already existing graph. See the R help function for the curve() command by entering ?curve() on the command line.