- 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 for Y variable at median in base R plot?
To create horizontal line for Y variable at median in base R plot, we can follow the below steps −
- First of all, create two vectors and plot them.
- Create the horizontal line at median using abline function.
Create the vectors and plot them
Let’s create two random vectors and plot them as shown below −
Example
x<-rnorm(20) y<-rnorm(20) plot(x,y)
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
Output
Create the horizontal line at median
Use abline function with h argument to create the horizontal line at median as shown below −
Example
x<-rnorm(20) y<-rnorm(20) plot(x,y) abline(h=median(y))
Output
- Related Articles
- How to create vertical line for X variable at median in base R plot
- How to create horizontal lines for each bar in a bar plot of base R?
- How to create a horizontal line in a histogram in base R?
- How to create bar plot in base R with different limits for Y-axis?
- How to create a plot with dashed regression line in base R?
- How to create a colored box for base R plot?
- How to create a plot with reversed Y-axis labels in base R?
- How to create a horizontal boxplot in base R?
- How to create a predictive linear regression line for a range of independent variable in base R?
- How to display average line for y variable using ggplot2 in R?
- How to create horizontal line in xyplot in R?
- How to create horizontal line for a range of values in a plot created by using ggplot2 in R?
- How to display the superscript for a single variable in a base R plot?
- How to create a vertical line in a time series plot in base R?\n
- How to create a dashed line that passes through Y = 1 in base R?

Advertisements