- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 create horizontal line in xyplot in R?
To create horizontal line in xyplot, we can use abline function.
For Example, if we have a data frame called df that contains two columns say X and Y and we want to create a scatterplot between X and Y using xyplot with a horizontal line at Y = 2 then we can use the command given below −
xyplot(Y~X,df,abline=c(h=2))
Example
Following snippet creates a sample data frame −
x<-rpois(20,2) y<-rpois(20,5) df<-data.frame(x,y) df
The following dataframe is created
x y 1 5 4 2 3 5 3 2 8 4 2 5 5 1 7 6 1 7 7 2 5 8 1 5 9 3 4 10 2 2 11 0 5 12 1 4 13 1 6 14 6 9 15 0 4 16 2 7 17 0 7 18 2 2 19 1 7 20 2 5
To load lattice package and create xyplot for x and y stored in df on the above created data frame, add the following code to the above snippet −
x<-rpois(20,2) y<-rpois(20,5) df<-data.frame(x,y) library(lattice) xyplot(y~x,df)
Output
If you execute all the above given snippets as a single program, it generates the following Output −
To create xyplot for x and y stored in df with horizontal at Y = 5 on the above created data frame, add the following code to the above snippet −
x<-rpois(20,2) y<-rpois(20,5) df<-data.frame(x,y) library(lattice) xyplot(y~x,df,abline=c(h=5))
Output
If you execute all the above given snippets as a single program, it generates the following Output −
- Related Articles
- How to create vertical line in xyplot in R?
- How to change the color of line in xyplot in R?
- How to create a horizontal line in a histogram in base R?
- How to create a dashed horizontal line in a ggplot2 graph in R?
- How to create a horizontal line in ggplot2 graph with larger width in R?
- How to create a horizontal line in ggplot2 graph with different color in R?
- How to create horizontal histogram in R?
- How to create horizontal line for Y variable at median in base R plot?
- How to Create the path element horizontal line in JavaFX?
- How to create a horizontal boxplot in base R?
- How to create horizontal legend using ggplot2 in R?
- How to create horizontal line for a range of values in a plot created by using ggplot2 in R?
- How to add a horizontal line in a boxplot created in base R?
- How to label points in scatterplot created by using xyplot in R?
- How to create a horizontal bar graph using ggplot2 in R?
