How to plot scatter plot using plot function in R?

This recipe helps you plot scatter plot using plot function in R

Recipe Objective

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.

Step 1 - Define the 2 vectors

x <- c(2,3,8,9,4,6,9,7,6,9) y <- c(3,9,5,6,8,6,5,8,9,3)

Step 2 - Plot the graph

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))

Step 3 - Find the correlation

corelation <- cor(x,y) corelation # the scatter plot shows a negative correlation between the two variables.
 "Correlation between the two variables is :" -0.259788098433717 

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Build a Customer Churn Prediction Model using Decision Trees
Develop a customer churn prediction model using decision tree machine learning algorithms and data science on streaming service data.

Build ARCH and GARCH Models in Time Series using Python
In this Project we will build an ARCH and a GARCH model using Python

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

Loan Eligibility Prediction in Python using H2O.ai
In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.

Time Series Python Project using Greykite and Neural Prophet
In this time series project, you will forecast Walmart sales over time using the powerful, fast, and flexible time series forecasting library Greykite that helps automate time series problems.

Time Series Classification Project for Elevator Failure Prediction
In this Time Series Project, you will predict the failure of elevators using IoT sensor data as a time series classification machine learning problem.

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch

MLOps Project to Deploy Resume Parser Model on Paperspace
In this MLOps project, you will learn how to deploy a Resume Parser Streamlit Application on Paperspace Private Cloud.