How to create bubble chart in R?

This recipe helps you create bubble chart in R

Recipe Objective

How to create a bubble chart in R? A bubble chart is a variant of the scatter plot where we compare the relationship between two continuous variables with one additional variable of size, that is the size of each data point. A bubble chart is a two-dimensional data visualization chart that displays data in the form of circles (bubbles). A bubble chart takes three variables of the data, namely the size of the bubble, horizontal and vertical location of the data points. This recipe demonstrates an example of a bubble chart using ggplot.

Step 1 - Import necessary libraries

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

Step 1 - Define a dataframe

**Syntax for bubble plot is-ggplot (data, aes (x,y, size))+geom_point ()** where, data — the required data to plot bubble chart aes (x=data,y=data,size)) — the aes function — creates bubble from data to geom geom_point — the geometric object to be drawn — bubble

# define two variables data = data.frame (x_data =c(2,4,6,8,10,12), y_data = c(10,20,30,40,50,60)) print(data)

Step 2 - Plot a bubble chart

ggplot(data, aes(x=x_data, y=y_data, size = x_data,col=x_data)) +geom_point() # the size of bubble differs as value increases the size of the bubbles/circles increases.

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Mastering A/B Testing: A Practical Guide for Production
In this A/B Testing for Machine Learning Project, you will gain hands-on experience in conducting A/B tests, analyzing statistical significance, and understanding the challenges of building a solution for A/B testing in a production environment.

Learn to Build an End-to-End Machine Learning Pipeline - Part 2
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, incorporating Hopsworks' feature store and Weights and Biases for model experimentation.

BigMart Sales Prediction ML Project in Python
The goal of the BigMart Sales Prediction ML project is to build and evaluate different predictive models and determine the sales of each product at a store.

Build a CNN Model with PyTorch for Image Classification
In this deep learning project, you will learn how to build an Image Classification Model using PyTorch CNN

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

Personalized Medicine: Redefining Cancer Treatment
In this Personalized Medicine Machine Learning Project you will learn to classify genetic mutations on the basis of medical literature into 9 classes.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Recommender System Machine Learning Project for Beginners-4
Collaborative Filtering Recommender System Project - Comparison of different model based and memory based methods to build recommendation system using collaborative filtering.

Build a Text Generator Model using Amazon SageMaker
In this Deep Learning Project, you will train a Text Generator Model on Amazon Reviews Dataset using LSTM Algorithm in PyTorch and deploy it on Amazon SageMaker.