How to plot scatter plot using plot function in R? Scatter plots are graphs that represent a relation between an independent variable (x) and a dependent variable (y). The plot represents data on a 2 dimensional plane, where dependent variable (y) is plotted on the Y-axis and an independent variable (x) is plotted on the X-axis. Scatter plots are used to explain the correlation between the two variables. There are mainly 3 cases in scatter plot correlation – - Positive correlation - Negative correlation - No correlation Scatter plots help us understand and visualize the data properly. This recipe demonstrates an example of scatter plots.
x <- c(2,3,8,9,4,6,9,7,6,9) y <- c(3,9,5,6,8,6,5,8,9,3)
Syntax for scatter plot - plot(x, y, main, xlab, ylab, xlim, ylim, axes) where, x - independent data points, y -independent data points, main - title of the correlation plot, xlab - title of the x axis, ylab - title of the y axis, xlim - limits for x axis data points, ylim - limits for y axis data points, axes - whether both the axes should be drawn on the plot.
plot(x,y,main="Correlation between x and y",xlab="x data points", ylab= "y data points", xlim=c(1,10),ylim=c(1,10))
corelation <- cor(x,y) corelation # the scatter plot shows a negative correlation between the two variables.
"Correlation between the two variables is :" -0.259788098433717