Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
points() is a generic function to draw a sequence of points at the specified coordinates. The lines() function creates
curves by joining a sequence of given points with line segments.
In the R script shown below, we plot the curves of three data sets (x,y1),(x,y2) and (x,y3) on the same plot. The code
and the plot are shown here:
# Add second curve to the same plot by calling points() and lines()
# Use symbol '*' for points.
points(xdata, y2, col="red", pch="*")
lines(xdata, y2, col="red",lty=2)
# Add Third curve to the same plot by calling points() and lines()
# Use symbol '+' for points.
points(xdata, y3, col="dark red",pch="+")
lines(xdata, y3, col="dark red", lty=3)
http://www.countbio.com/web_pages/left_object/R_for_biology/R_fundamentals/multiple... 4/19/2020
R tutorials, multiple curves, multiple plots, same plot R Page 2 of 3
Legends can be added to describe the different curves in the plot. For this, we call the legend() function after plotting
the curves. This funciton adds a legend box with appropriate legends at a desired location inside the plot. Some of
the important parameters of the legend() function are:
col -----> A vector of colors for 'col' parameter. These colors are same as the one
used in the graph
pch -----> A vector of character symbols for 'pch' parameter, same as the ones
used as 'pch' parameters in the plots.
lty -----> A vector of line types to be given to 'lty' parameter, same as the one
used for plotting curved
ncol -----> Number of columns for writing the legends. Default is one column.
While typing the vectors for legend, col and pch, the order of the plot types
have to be maintained.
Carefully note the example code below which adds legend to the plot. The resulting figure has three curves with a
legend box:
# Add second curve to the same plot by calling points() and lines()
# Use symbol '*' for points.
http://www.countbio.com/web_pages/left_object/R_for_biology/R_fundamentals/multiple... 4/19/2020
R tutorials, multiple curves, multiple plots, same plot R Page 3 of 3
# Add Third curve to the same plot by calling points() and lines()
# Use symbol '+' for points.
points(xdata, y3, col="dark red",pch="+")
lines(xdata, y3, col="dark red", lty=3)
http://www.countbio.com/web_pages/left_object/R_for_biology/R_fundamentals/multiple... 4/19/2020