By default, the plot sets the axis limits to fit the data given it. Notice that the range of the plot does not expand to include all of the line plotted by the lines command. (The last y.intersp argument just increases the vertical spacing of the legend.) The first two arguments to the legend command are its position, the next is the legend text, and the following two are just vectors of the same arguments of the plot and lines commands, as R requires you to specify them again for the legend. The last two lines add a title (since it wasn't added with a main argument of the plot command) and a legend. > plot(t,z, type="l", col="green", lwd=5, xlab="time", ylab="concentration") One way to plot separate lines for both $z$ and $w$ is to first plot $z$ with the plot and then add a line for $w$ with the lines command. Imagine that you wanted to plot not only $z$ but also a variable $w$ that was increasing with time. > plot(t,z, type="l", col="green", lwd=5, xlab="time", ylab="concentration", main="Exponential decay") A line plot with multiple series Here, we use type="l" to plot a line rather than symbols, change the color to green, make the line width be 5, specify different labels for the $x$ and $y$ axis, and add a title (with the main argument). The plot command accepts many arguments to change the look of the graph. Without any other arguments, R plots the data with circles and uses the variable names for the axis labels. The simplest R command to plot $z$ versus $t$ is Imagine that in R, we created a variable $t$ for time points and a variable $z$ that showed a quantity that is decaying in time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |