How to change histogram bins in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# How to change histogram bins in R?

This recipe helps you change histogram bins in R

## Recipe Objective

How to change histogram bins in R? A histogram plots a graph of continuous value variable with their corresponding frequencies. The data is plotted as bars of different heights. The difference between bar plot and histogram is that the bar charts are plotted for discrete data, whereas a histogram is plotted for continuous data. A histogram provides a visual representation of the distribution of data, which helps us to know whether the data is symmetric or skewed in nature. It also displays if there are any outliners in my dataset. breaks parameter changes the histogram bins in an R code. This recipe demonstrates an example of histogram.

## Step 1 - Define a vector

Syntax for histogram - hist(x, main, xlab, xlim, ylim, breaks,col) where, x - defined vector main - title of the histogram xlab - title to the X axis xlim - range of values on X -axis ylim - range of values on Y -axis breaks - mention the width/bin size of each bar col - colour of the bars

``` x <- c(1,5,6,3,9,7,2,8,9,7,5,1) ```

## Step 2 - Plot a histogram

Here , the histogram returns the frequency bars of the given vector for a continuous range of values.

``` hist(x,main="Histogram plot",xlab="data points for x",xlim=c(0,10),ylim=c(0,5),breaks=5,col='blue') # number of bins = 5 hist(x,main="Histogram plot",xlab="data points for x",xlim=c(0,10),ylim=c(0,5),breaks=8,col='red') # number of bins = 8 ```

#### Relevant Projects

##### Avocado Machine Learning Project Python for Price Prediction
In this ML Project, you will use the Avocado dataset to build a machine learning model to predict the average price of avocado which is continuous in nature based on region and varieties of avocado.

##### Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

##### Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

##### Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

##### Abstractive Text Summarization using Transformers-BART Model
Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

##### 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 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.

##### Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

##### Machine learning for Retail Price Recommendation with Python
Use the Mercari Dataset with dynamic pricing to build a price recommendation algorithm using machine learning in Python to automatically suggest the right product prices.

##### PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.