- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How to label points in scatterplot created by using xyplot in R?

To label points in scatterplot created by using xyplot, we can follow the below steps −

- First of all, creating two numerical and one categorical vector.
- Loading lattice package and creating scatterplot.
- Creating the scatterplot with points labelled using categorical vector by panel.xyplot and ltext function.

## Creating the vectors

Create three vectors, one categorical and two numerical −

x<-sample(1:10,5) y<-sample(1:10,5) Dots<-c("A","B","C","D","E") x y Dots

On executing, the above script generates the below output(this output will vary on your system due to randomization) −

[1] 7 3 2 10 5 [1] 1 2 5 4 8 [1] "A" "B" "C" "D" "E"

## Loading lattice package and creating scatterplot

Use xyplot function to create the scatterplot between x and y −

library(lattice) xyplot(y~x,data=data.frame(x,y),pch=20,cex=2)

### Output

## Creating the scatterplot with labels

Use panel.xyplot and ltext to create the scatterplot with labels −

x<-sample(1:10,5) y<-sample(1:10,5) Dots<-c("A","B","C","D","E") xyplot(y~x,data=data.frame(x,y),pch=20,cex=2,panel=function(x,y,...){ + panel.xyplot(x,y,...); + ltext(x=x,y=y,labels=Dots,pos=1)})

### Output

- Related Questions & Answers
- How to create regression model line in a scatterplot created by using ggplot2 in R?
- How to reverse the X-axis labels of scatterplot created by using ggplot2 in R?
- How to change the border color of points in a scatterplot created with ggplot2 in R?
- How to create a scatterplot with dark points using ggplot2 in R?
- How to create a scatterplot in R using ggplot2 with transparency of points?
- How to color scatterplot points based on a threshold using ggplot2 in R?
- How to change the color of points in a scatterplot using ggplot2 in R?
- How to add a mathematical expression in axis label in a plot created by using plot function in R?
- How to create a scatterplot in R using ggplot2 with different designs of points?
- How to change the default type of points for scatterplot using ggplot2 in R?
- How to create a scatterplot with low intensity of points using ggplot2 in R?
- How to display NA group values in scatterplot created with ggplot2 using color brewer in R?
- How to add a vertical line with some value on a scatterplot created by ggplot2 in R?
- How to join points on a scatterplot with smooth lines in R using plot function?
- How to change the color of points for ggplot2 scatterplot using color brewer in R?

Advertisements