How to create a bar chart using lattice package in R?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# How to create a bar chart using lattice package in R?

This recipe helps you create a bar chart using lattice package in R

## Recipe Objective

How to create a bar chart using a lattice package in R? Bar charts are a graphical representation of categorical or discrete type of data. The data is represented in the form of rectangular bars either horizontally or vertically on the graph. Bar graphs can be used to compare different categories of data over a time period. Lattice is a data visualization and graphics package in R — graph_type (formula, data) This recipe demonstrates an example on a bar chart.

## Step 1 - Install necessary package and library

``` install.packages("lattice") library(lattice) ```

## Step 2 - Create a dataframe

``` data <- data.frame(x = c(10,5,6,15,20,19), type = c("A","B","C","D","E","F")) print(data) "Data is :" print(data) x type 1 10 A 2 5 B 3 6 C 4 15 D 5 20 E 6 19 F ```

## Step 3 - Plot a bar chart

syntax - barchart(x,data,main,xlab,ylab) x - the categorical data value data - the input data main - the title of the chart xlab - the title of the x axis ylab - the title of the y axis

``` barchart(x~type, data=data, main="Bar chart", xlab="x_values", ylab="type") ```
``` " Output of the code is :"

```

#### Relevant Projects

##### Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

##### Inventory Demand Forecasting using Machine Learning in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

##### Churn Prediction in Telecom using Machine Learning in R
Estimating churners before they discontinue using a product or service is extremely important. In this ML project, you will develop a churn prediction model in telecom to predict customers who are most likely subject to churn.

##### Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

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

##### 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 Music Recommendation Algorithm using KKBox's Dataset
Music Recommendation Project using Machine Learning - Use the KKBox dataset to predict the chances of a user listening to a song again after their very first noticeable listening event.

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

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

##### Loan Eligibility Prediction in Python using H2O.ai
In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.