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

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

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.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Deploying Machine Learning Models with Flask for Beginners
In this MLOps on GCP project you will learn to deploy a sales forecasting ML Model using Flask.

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.

PyCaret Project to Build and Deploy an ML App using Streamlit
In this PyCaret Project, you will build a customer segmentation model with PyCaret and deploy the machine learning application using Streamlit.

Build an AI Chatbot from Scratch using Keras Sequential Model
In this NLP Project, you will learn how to build an AI Chatbot from Scratch using Keras Sequential Model.

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.

Build a Churn Prediction Model using Ensemble Learning
Learn how to build ensemble machine learning models like Random Forest, Adaboost, and Gradient Boosting for Customer Churn Prediction using Python