The following is an introduction for plotting simple graphs with the R Programming Language. Each example builds on the previous one.
In statistic while trying to do analysis on data the most important way of displaying information is the use of graphs. so let's see different kind of graph we can plot with codes.
First we'll produce a very simple graph using the values in the weight vector:
copy the following codes
# Define the cars vector with 8 values weight <- c(1, 6, 11, 14, 19, 22, 26, 33) # Graph the weight vector with all defaults plot(weight)
Let's add a title, a line to connect the points, and some color with the following codes
weight <- c(1, 6, 11, 14, 19, 22, 26, 33) # Graph weight using red points overlay by a line and use o as the dot plot(weight, type="o", col="red",font.main=11) # Create a title with a green, bold font title(main="Autos", col.main="red", font.main=4)
plot() function is used to plot the graph. it can take some parameters like vector ,type and color.
Vectors: is the data will want to use to plot the graph.
type: is the kind of mark and line we want to use to specify dot on the graph. it is dot by default and can be change to whatever we want e.g "h","p","s",'S','l' and 'c'
color: this is use to give our own preference color.
can we plot two line graph in one graph?? Yeah! we can and we shall take a look at that later. read the next article.