Browse By

R Language –Presentation of Data : Online Course

R Scatter Plot

  • The scatter plots are used to compare variables.
  • Comparison between variables is meant to define how much one variable is affected by another variable.
  • In a scatter plot, the data is represented as a collection of points and  plots one point for each observation..
  • Each point on the scatter plot defines the values of the two variables.
  • One variable is selected for the vertical axis and other for the horizontal axis.
  • The simple scatter plot is created using the plot() function. 

There is the following syntax for creating scatter plot in R:

Plot(x,y,…)

And its complete syntax is:

plot(x, y, type, main, sub,  xlab, ylab)

Some arguments of the plot() function:

Following arguments in details.

S.NOPARAMETERDESCRIPTION
1.vIt is a vector which contains the numeric values. x is specifies points on the x-axis. y is specifies points on the y-axis.
2.typechange the plot type. It accepts the following strings and has the given effect.”p” – points
“l” – lines
“b” – both points and lines
“c” – empty points joined by lines
“o” – overplotted points and lines
“s” and “S” – stair steps
“h” – histogram-like vertical lines
“n” – does not produce any points or lines
3.xlabIt is the label for the x-axis.
4.ylabIt is the label for the y-axis.
5.mainIt is the title of the chart.
6.colIt is used to give the color for both the points and lines
7pchpch is used to change the point shape format.
8cexUse cex=number to change the size of the points
9Legend()Legend takes as input the coordinates, text and the symbols to be interpreted.
10Itylty is the text sequence of four numbers from 1 to 9, for example: lty = “4241”.