The lattice package in R Programming provides **xyplot** to draw Scatter Plot. This lattice scatter plot in R is very useful to visualize the relationship between two sets of data. You can call this R Scatter Plot as scatter chart, scatter graph, scatter gram, or scatter diagram.

For example, to visualize the Salary against Experience use this Scatter Plot. In this article, we will show you, How to Create Lattice Scatter Plot in R, Format its colour, shape etc with an example.

## Lattice Scatter Plot in R Syntax

The basic syntax to draw the Lattice scatter chart, or Lattice Scatter Plot in R Programming is as shown below

xyplot(x, data, ...)

and the complex syntax is:

xyplot(x, data, allow.multiple = is.null(groups) || outer, outer = !is.null(groups), auto.key = FALSE, aspect = "fill", panel = lattice.getOption("panel.xyplot"), prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, drop.unused.levels = lattice.getOption("drop.unused.levels"), ..., lattice.options = NULL, default.scales, default.prepanel = lattice.getOption("prepanel.default.xyplot"), subscripts = !is.null(groups), subset = TRUE)

For this, we are going to use the* diamonds *data set that is provided by the R, and the data inside this dataset is:

## Create Lattice Scatter Plot in R

In this example, we will show you, How to use this xyplot function in the lattice package to create a Scatter Plot. For this, we are using the diamonds data set, which is provided by the R Studio. If the requirement is to import data from external files, I suggest you refer R Read CSV article to understand the CSV file import

# Create R Scatter Plot using Lattice package # Importing the lattice library library(lattice) # Creating Scatter Plot xyplot(price ~ carat, data = diamonds)

**OUTPUT**

### Assign names to Scatter plot in R Lattice

This example show you, How to use * main, xlab, and ylab *to assign names to lattice scatter plot, X-Axis, Y-Axis, and individual bars

**main:**Main Title for your scatter plot.**xlab:**Label for X-Axis**ylab:**Label for Y-Axis

# Change Names of a Lattice Scatter Plot in R # Importing the lattice library library(lattice) # Creating Scatter Plot xyplot(price ~ carat, data = diamonds, main = "Lattice Scatter Plot in R", xlab = "No of Carats", ylab = "Pricing")

**OUTPUT**

### Change Shape, and Color of Lattice Scatter plot in R

In this example, we will show you, How to change the shape, and colour of a lattice scatter plot in R using * col*, and

*arguments.*

**cex****col:**Please specify the colour you want to use in your Scatterplot.**cex:**Specify the size of the point(s)**pch:**To change shape.

# Change Shapes, Colors of a Lattice Scatter Plot in R # Importing the lattice library library(lattice) # Creating Scatter Plot xyplot(price ~ carat, data = diamonds, main = "Lattice Scatter Plot in R", xlab = "No of Carats", ylab = "Pricing", col = "chocolate", cex = 0.8, pch = 8)

**OUTPUT**

## Multiple Lattice Scatter Plots in R

In this example, we will show you, How to divide the scatter plot using groups.

# Linear Progression on a Lattice Scatter Plot in R # Importing the lattice library library(lattice) # Creating Scatter Plot xyplot(price ~ carat | cut, data = diamonds, main = "Lattice Scatter Plot in R", xlab = "No of Carats", ylab = "Pricing", col = "chocolate", cex = 0.8, pch = 8)

Here, Scatter plot is dividing based on the Cut.

Thank You for Visiting Our Blog