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

# How to create a scatter plot using lattice package in R?

This recipe helps you create a scatter plot using lattice package in R

Scatter plot is the simplest chart which uses cartesian coordinates to display the relation between two variables x and y. It is used to find any trend or relationship between the two variable.

In this recipe we are going to use Lattice package to plot the required scatter plot. Lattice package provides powerful data visualisation functions which is mainly used for statistical graphics of multivariate data. It is pre-installed in R and is inspired by trellis graphics.

This recipe demonstrates how to plot a simple scatter plot in R using lattice package.

Dataset description: It is the basic data about the customers going to the supermarket mall. The variables that we are interested in: Annual.Income (which is in 1000s), Spending Score and age

```
# Data manipulation package
library(tidyverse)
# Lattice package for data visualisation
install.packages("lattice")
library(lattice)
# reading a dataset
customer_seg = read.csv('R_145_Mall_Customers.csv')
glimpse(customer_seg)
```

Observations: 200 Variables: 5 $ CustomerID1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,… $ Gender Male, Male, Female, Female, Female, Female, Fe… $ Age 19, 21, 20, 23, 31, 22, 35, 23, 64, 30, 67, 35… $ Annual.Income..k.. 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 19, 19… $ Spending.Score..1.100. 39, 81, 6, 77, 40, 76, 6, 94, 3, 72, 14, 99, 1…

We use the xyplot() function to plot a scatter plot between annual income and spending score variables.

Syntax: xyplot(x, data, main = , group = )

where:

- x = variables to be plotted ( "y-axis variable" ~ "x -axis variable")
- data = dataframe to be used
- main = gives the title to the plot
- group = group the points based on a factor variable

```
xyplot(Annual.Income..k.. ~ Spending.Score..1.100.,
data = customer_seg,
group = Gender,
auto.key = TRUE)
```

In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

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.

Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Use the Adult Income dataset to predict whether income exceeds 50K yr based on
census data.

PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

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.

Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.