Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Create a Plot Matrix of Scatterplots in R Programming - pairs() Function
Next article icon

Create a Plot Matrix of Scatterplots in R Programming - pairs() Function

Last Updated : 10 Dec, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

pairs() function in R language is used to return a plot matrix, consisting of scatter plots corresponding to each data frame.

R - Create Plot Matrix of Scatterplots

Syntax: pairs(data)

Parameters: 

  • data: It is defined as  value of pairs Plot.

Returns: Color, Labels, Panels, and by Group in pairs plot. 
 

Create Plot Matrix of Scatterplots in R

Example 1: Basic example of R - pairs() Function 

R
# Set seed for reproducibility set.seed(425340)  # Sample size of 800 N <- 800  # Create variable x1 <- rnorm(N)  # Create correlated variable x2 <- x1 + rnorm(N, 0, 4)  # Create another correlated variable x3 <- 2 * x1 - x2 + rnorm(N, 0, 3)      data <- data.frame(x1, x2, x3)     pairs(data)             

Output: 

Here, in the above example, the diagonal shows the names of the three numeric variables. The middle graphic in the first-row shows the relation between x1 and x2 whereas the right graph in the first row shows the relation between x1 and x3 and so on.

Example 2: Another example to select Variables of pairs Plot 

R
# Set seed for reproducibility set.seed(425340)  # Sample size of 800 N <- 800      # Create variable x1 <- rnorm(N)  # Create correlated variable x2 <- x1 + rnorm(N, 0, 4)              # Create another correlated variable x3 <- 2 * x1 - x2 + rnorm(N, 0, 3)      data <- data.frame(x1, x2, x3)      pairs(~ x1 + x3, data = data)     

Output:

Example 3: Another example with implementation to Modify Color, Shape of Points, Labels and Title

R
# Set seed for reproducibility set.seed(425340)  # Sample size of 800 N <- 800  # Create variable x1 <- rnorm(N)  # Create correlated variable x2 <- x1 + rnorm(N, 0, 4)  # Create another correlated variable x3 <- 2 * x1 - x2 + rnorm(N, 0, 3)      data <- data.frame(x1, x2, x3)      pairs(~ x1 + x2 + x3, data = data) pairs(~ x1 + x3, data = data)     pairs(data[, 1:3],     col = "darkgreen", # Change color                         pch = 18,             # Change shape of points              # Change labels of diagonal     labels = c("var1", "var2", "var3"),     main = " pairs plot in R") 

Output:


Next Article
Create a Plot Matrix of Scatterplots in R Programming - pairs() Function

K

kaurbal1698
Improve
Article Tags :
  • R Language
  • R Plot-Function

Similar Reads

    Create a Matrix of Scatterplots (pairs() Equivalent) in ggplot2
    Visualizing relationships between multiple variables simultaneously can be challenging. In base R, the pairs() function is often used to create a matrix of scatterplots, showing pairwise relationships between all columns in a data frame. However, for those who prefer the flexibility and aesthetics o
    3 min read
    Addition of more points to a Plot in R Programming - points() Function
    points() function in R Language is used to add a group of points of specified shapes, size and color to an existing plot. Syntax: points(x, y, cex, pch, col) Parameters: x, y: Vector of coordinates cex: size of points pch: shape of points col: color of points Sample Scatter Plot: Python3 1== # R pro
    2 min read
    Addition of Lines to a Plot in R Programming - lines() Function
    In R, the lines() function is called to add on top of already existing plot. This is particularly helpful when you want to add more lines, such as trend lines, regression lines, or special lines, on a plot. The lines() function allows flexibility in line color, line width, and line type, with multip
    3 min read
    Create a Heatmap in R Programming - heatmap() Function
    A heatmap() function in R Programming Language is used to plot a heatmap. A heatmap is defined as a graphical representation of data using colors to visualize the value of the matrix. It is used to represent more common values or higher activities brighter colors reddish colors are used and to less
    3 min read
    Plotting of Data using Generic plots in R Programming - plot() Function
    In this article, we will discuss how we plot data using Generic plots in R Programming Language using plot() Function. plot functionplot() function in R Programming Language is defined as a generic function for plotting. It can be used to create basic graphs of a different type. Syntax: plot(x, y, t
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences