classblogs:as2011:r_dictionary
Plot three lines in one figure
In this example, I will plot three lines in one figure as shown in class.
active<-read.table('http://nd.psychstat.org/_media/classdata/active.txt', header=T, na.string='99999')
plot(1:4, active[5,9:12], type='o', lty=1, col='black', ylim=c(0,40), xlab='Time',ylab='HVLTT')
lines(1:4, active[10,9:12], type='o', lty=2, col='red')
lines(1:4, active[15,9:12], type='o', lty=3, col='blue')
legend('bottomleft', c('5th', '10th', '15th'), lty=c(1,2,3), col=c('black', 'red', 'blue'))
In the codes, the function plot() generates a new figure and the function lines() adds a figure to an existing figure. In both plot() and lines(), the meaning of the arguments is given below.
type='o' gives the type of the plot. The following values are possible: “p” for points, “l” for lines, “o” for overplotted points and lineslty=specifies the line type. Line types can either be specified as an integer (0=blank, 1=solid (default), 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash) or as one of the character strings “blank”, “solid”, “dashed”, “dotted”, “dotdash”, “longdash”, or “twodash”, where “blank” uses ‘invisible lines’ (i.e., does not draw them).col=The colors for lines and points. Color types can be specified as an integer or character strings “black”, “red”, “blue”, etc.ylim=c(0,40)the y limits of the plot. This example gives the minimum value 0 and maximum value 40.xlab=a label for the x axisylab=a label for the y axis
The function legend() can be used to add legends to plots. The commonly used options for the function are
bottomleft: the place of the legend. Can be “bottomright”, “topleft”, “topright”.c('5th', '10th', '15th')gives a list of names for each legend. Names are connected byc.lty=, types of linescol=, colors of legend.
You could leave a comment if you were logged in.
classblogs/as2011/r_dictionary.txt · Last modified: by 127.0.0.1

