The lattice package in R Programming provides **xyplot** to draw Scatter Plot. This plot is very useful to visualize the relationship between two sets of data. You can call this 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 color, shape etc with 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 lattice package to create a scatter Plot. For this, we are uisng the diamonds data set, which is provided by the R Studio. If the requirement is to import data from external files, I suggest you to 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 color of a lattice scatter plot using * col*, and

*arguments.*

**cex****col:**Please specify the color you want to use in your Scatter plot.**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

## Leave a Reply