- 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 lines with two different colors after a threshold in R?
To create two horizontal lines with different color after a threshold in R, we can follow the below steps −
- First of all, create a plot in base R.
- Then, add a line to the plot using abline function.
- After that, use segments function to partially change the color of the line.
Create the plot
Using plot function to create a plot in base R −
plot(1:5,1:5,xlim=c(0,5))
Output
Add a line to the plot
Using abline function to add a line to the plot −
plot(1:5,1:5,xlim=c(0,5)) abline(h=3)
Output
Partially color the line
Using segments function to color the with yellow color starting from 0 to 3 −
plot(1:5,1:5,xlim=c(0,5)) abline(h=3) segments(x0=0,y0=3,x1=2,y1=3,col="yellow")
Output
- Related Articles
- How to create density plot for categories filled with different colors in R?
- How to create a horizontal line in ggplot2 graph with different color in R?
- How to create boxplot with horizontal lines on the minimum and maximum in R?
- How to display legend in base R with different colors?
- How to create a scatterplot with colors as group in R?
- How to create horizontal lines for each bar in a bar plot of base R?
- How to create a circle with vertical lines in R?
- How to fill histogram bars using ggplot2 in R with different colors?
- How to create a plot using rgb colors in R?
- How to create a scatterplot with colors of the group of points in R?
- How to create two vertical lines on a plot with shaded area in-between using R?
- How to create horizontal histogram in R?
- How to create progress bar in different colors in Bootstrap
- How to create a horizontal boxplot in base R?
- How to create bar plot with gradient colors using ggplot2 in R?\n

Advertisements