How to plot pie chart using ggplot in R?

This recipe helps you plot pie chart using ggplot in R

Recipe Objective

How to plot a pie chart using ggplot in R? A pie chart is a circular garph, that represents data. It is a pictorial representation of the data. In a pie chart,the chart is divided into slices, where each slice is a proportional part of the whole data. The pie chart is a very useful tool for data analysis. ggplot is a package in R that helps in data visualization. This recipe demonstrates an example of pie charts using the ggplot.

Step 1 - Install necessary libraries

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

Step 1 - Define a dataframe

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

data <- data.frame("category" = c('A', 'B', 'C', 'D','E'), "values" = c(10, 20, 30, 40, 50)) print(data)

Step 2 - Plot the pie chart

ggplot(data, aes(x="", y=values, fill=category)) + geom_bar(stat="identity", width=1) + coord_polar("y", start=0)

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Tensorflow Transfer Learning Model for Image Classification
Image Classification Project - Build an Image Classification Model on a Dataset of T-Shirt Images for Binary Classification

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.

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

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

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.

Build an Image Segmentation Model using Amazon SageMaker
In this Machine Learning Project, you will learn to implement the UNet Architecture and build an Image Segmentation Model using Amazon SageMaker

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

Create Your First Chatbot with RASA NLU Model and Python
Learn the basic aspects of chatbot development and open source conversational AI RASA to create a simple AI powered chatbot on your own.

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

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python