How to create an interactive scatter plot in ggplot in R

This recipe helps you create an interactive scatter plot in ggplot in R

Recipe Objective

How to create an interactive scatter plot in ggplot ? 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 Y-axis and 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. ggplot is an R package for data visualization This recipe demonstrates an example on scatter plots using ggplot. .

Step 1 - Import necessary libraries

library("ggplot2") library("dplyr")

Step 1 - Define a dataframe

**Syntax for scatter plots using ggplot is- ggplot (data, aes (x=,y=)+geom_point ()** where, data — the required data to be plotted in a pie chart aes (x=data,y=data)) — the aes function — creates mapping from data to geom geom_point — the geometric object to be drawn.

# define two variables data = data.frame (x_data =c(2,3,8,9,4,6,9,7,6,9), y_data = c(3,9,5,6,8,6,5,8,9,3)) print(data)

Step 2 - Plot a scatter plot

ggplot(data = data, aes(x = x_data, y = y_data)) + geom_point(color = 'blue')

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Learn How to Build PyTorch Neural Networks from Scratch
In this deep learning project, you will learn how to build PyTorch neural networks from scratch.

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

Llama2 Project for MetaData Generation using FAISS and RAGs
In this LLM Llama2 Project, you will automate metadata generation using Llama2, RAGs, and AWS to reduce manual efforts.

Word2Vec and FastText Word Embedding with Gensim in Python
In this NLP Project, you will learn how to use the popular topic modelling library Gensim for implementing two state-of-the-art word embedding methods Word2Vec and FastText models.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

Hands-On Approach to Master PyTorch Tensors with Examples
In this deep learning project, you will learn how to perform various operations on the building block of PyTorch : Tensors.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.