How to plot pie chart using ggplot in R?

How to plot pie chart using ggplot in R?

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)

Relevant Projects

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.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

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

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

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

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.