R has very powerful and easy to use plotting functions. Unfortunately, they are not very intuitive and can be quite confusing for beginners. For starters, here's a very simple plot.
a <- c(60,164,164,100,62,44,26,174,106,146,102,50,152,86,166) plot(a)

All numeric values are placed in a vector a. Then we plot and R uses default settings to plot the graph. Now we add labels to the graph.
plot(a, ylab="Number of Nodes", xlab="Spectra", main="Window Filter Analysis")

Pretty straightforward, isn't it. Now let's plot a line instead of points on the graph.
plot(a, ylab="Number of Nodes", xlab="Spectra", main="Window Filter Analysis", type="l")

To draw a line, all we need to do is specify type="l". Other options include b, c, h, o, p, s. They are plotted below.
![]() |
![]() |
| type="b" | type="c" |
![]() |
![]() |
| type="h" | type="o" |
![]() |
![]() |
| type="p" | type="s" |
Plotting multiple data sets on a graph
It is very often common to plot multiple data sets on a graph. Such graphs often give useful insight into how the two data set differ or resemble each other. Unfortunately, plot() function cannot be used to plot two data sets. Thus, we have to work around the problem by using another function lines(). points() function can also be used.
a <- c(60,164,164,100,62,44,26,174,106,146,102,50,152,86,166) b <- c(26,44,50,62,86,106,60,102,100,146,166,174,164,152,164) > plot(a, ylab="Number of Nodes", xlab="Spectra", main="Window Filter Analysis", type="o") > lines(b,col="red") > points(b,col="red")

The plot() function draws the points and line graph. lines() function draws a line in red color. points() function draws the red points.
For more information on these functions:
help("plot")
help("points")
help("lines")





