 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 display legend in base R with different colors?
To display legend in base R with different colors, we can follow the below steps −
- First of all, create a plot using plot function. 
- Then, use legend function legend argument and col argument to display legend with different colors. 
Example
Create the plot
Let’s create a plot of a vector x using plot function −
x<-rpois(5,5) plot(x)
Output

Display legend with different colors
Using legend function legend argument and col argument to display legend with red and blue colors −
x<-rpois(5,5) legend("topleft",legend=c("Less than 5","Greater than 5"),pch=15,col=c("red","blue")) Output

Advertisements
 