8.1 Basic Plots
This example follows from a previous tutorial about user-defined functions in subsection 6.3.
Suppose you a function called compound that has two arguments \(i\) and \(t\).
<- function(i, t){
compound 1 + i)^t
( }
Specifically define \(i1 = 0.05\) and \(t\) as a sequence of numbers between 0 and 10 inclusive by an increment of \(1/4\). Let \(A1\) be the value of the function multiplied by 1000 at each time increment.
<- 0.05
i1
<- seq(0, 10, 1/4)
t
<- 1000*compound(i1, t) A1
We can plot \(A1\) vs. \(t\) with the plot() function:
plot(t, A1)
Your plot appears in the bottom right corner of RStudio in the Plots tab. Note that the order \((t, A1)\) indicates that \(t\) is on the \(x-axis\) and \(A1\) is on the \(y-axis\). Check to see what happens if you reverse \((t, A1)\) and plot that result.
All of the 41 values of \(A1\) are plotted on the chart, with R automatically deciding on the numbers plotted on the x-axis and y-axis.