- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 represent the legend in a plot created by using plot function with colored straight lines or stars in R?
A legend helps us to differentiate between the type of values or any another division of values in a data set. These legends can be represented in many ways and two of these ways are straight lines and stars. To represent the legend in a plot created by using plot function with colored straight lines or stars, we need to correct lty and pch arguments.
Example
Consider the below vectors −
set.seed(199) x<-rnorm(10,2,1) y<-rnorm(10,2,0.04)
Creating the plot between x and y with colored lines legend values −
plot(x,y) legend("bottomright",legend=c("Above 2","Between 1.95 and 2","Below 1.95"), + lwd=2,cex=0.75,col=c("black","blue","red"),lty=c(1,1,1))
Output
Creating the plot between x and y with colored stars legend values −
plot(x,y) legend("bottomright",legend=c("Above 2","Between 1.95 and 2","Below 1.95"), + lwd=2,cex=0.75,col=c("black","blue","red"),lty=c(NA,NA,NA),pch=c(8,8,8))
Output
- Related Articles
- How to reduce the size of the area covered by legend in R for a plot created by using plot function?
- How to change legend values in a bar plot created by using ggplot2 in R?
- How to change the background color of a plot created by using plot function in R?
- How to remove the border of the legend of a chart created by plot function in R?
- How to remove the boxes around legend of a plot created by ggplot2 in R?
- How to create gridlines that matches with Y-axis values in the plot created by using plot function in R?
- How to add a mathematical expression in axis label in a plot created by using plot function in R?
- How to write the plot title in multiple lines using plot function in R?
- How to display the legend of a bar plot in a colored box in R?
- How to change the color and size of the axes labels of a plot created by using plot function in R?
- How to change the title of a graph to italic created by using plot function in R?
- How to create a plot in R with gridlines using plot function?
- How to change the position of the title of a plot which is created using plot function in R?
- How to remove ticks in a plot created by using gglot2 in R?
- How to create a plot in R with a different plot window size using plot function?

Advertisements