######################################################################### # # # plot.R <- an R script for plotting a function # # @ http://www.srcf.ucam.org/~lj237/plot.R # # # # Open this file from R by saving it somewhere and clicking "Open # # script" in the file menu. Anything in this file starting with # is a # # 'comment', i.e. something that doesn't do anything, just me talking # # to you. Anything without a # is an R command, which does something. # # # # By Luke, 16/10/07 # # # ######################################################################### t <- seq(start=-0.5,end=10,len=500) # "t <-" means "assign to t", and the seq() command puts 500 numbers # between -0.5 and 10 into t Y <- t*exp(-t) # this performs the operation ("times x by exp(-x)") on all the objects # in t, and stores all the answers in Y plot(t,y,type="l",axes=FALSE,main=expression(Y==t*e^-t)) # the plot() command plots all the numbers in t and y against each # other. 'type="l"' says that we want a line graph, and saying # "axes = FALSE" means that it won't put on any axis (we will add # these later). Finally, the "main =" part tells R what title we want, # and the expression() command says we want it as an equation axis(side=1,pos=0) axis(side=2,pos=0) # finally, calling this command twice puts an axes at position 0 (i.e. t=0 # or y=0) on two sides (1 is the bottom one, 2 is along the side)