Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python – Data visualization
  • Pandas
  • Seaborn
  • Matplotlib
  • Plotly
  • Altair
  • Bokeh
  • Pygal
  • Exploratory Data Analysis
  • Power BI
  • Tableau
  • Data Analysis with Python
  • Python Interview Questions
  • Machine Learning
  • Deep Learning
  • Natural Language Processing
  • Data Science
  • R Programming
Open In App
Next Article:
How to create a boxplots using lattice package in R?
Next article icon

How to create a scatter plot using lattice package in R?

Last Updated : 11 Jul, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss how to create the scatter plots using lattice package in R programming language.

In R programming, the Lattice package is a data visualization library that consists of various functions to plot different kinds of plots. Using the lattice library we can able to plot various kinds of plots like scatter plot, Box plots, Histograms, 3D scatter plots, Dot plots, Strip plots, Density plots, etc. In order to use the functionalities of the lattice library need to import the library first.

To import the lattice library use the below statement-

library(lattice)

Scatter plot using lattice package in R

In R, The Lattice library contains xyplot() method that is used to create a scatter plot. In order to use the xyplot() method, the lattice library needs to be imported first. The syntax of xyplot() method is given below-

Syntax: xyplot( col1~col2, data=dataframeName)

Let's look into a couple of examples on how to plot the box plot using lattice library.

Example 1: In the below code we created a data frame "stats" and plotted a scatter plot between data in two columns using xyplot() method.

R
# import lattice library library(lattice)  # create a data frame  stats <- data.frame(player=c('A', 'B', 'C', 'A',                              'B', 'C', 'A', 'B',                               'C'),                runs=c(200, 100, 100, 150, 109,                        200, 270, 120, 76),                wickets=c(5, 1, 6, 2, 4, 2, 0, 8,                          1))  print("stats Dataframe") stats  # groped scatter plot  xyplot(runs ~ wickets, data = stats) 

Output

"stats Dataframe"   player runs wickets  1      A  200       5  2      B  100       1  3      C  100       6  4      A  150       2  5      B  109       4  6      C  200       2  7      A  270       0  8      B  120       8  9      C   76       1
 

Example 2: In this example, we plotted a grouped scatter plot for the above-created data frame using xyplot() method.

R
# import lattice library library(lattice)  # create a data frame  stats <- data.frame(player=c('A', 'B', 'C', 'A',                              'B', 'C', 'A', 'B',                               'C'),                runs=c(200, 100, 100, 150, 109,                       200, 270, 120, 76),                wickets=c(5, 1, 6, 2, 4,                           2, 0, 8, 1))                 # groped scatter plot  xyplot(runs ~ wickets, data = stats, group = player, auto.key = TRUE) 

Output

 

Next Article
How to create a boxplots using lattice package in R?

R

rahulkl8471
Improve
Article Tags :
  • R Language
  • Data Visualization
  • R-Packages

Similar Reads

  • How to create a boxplots using lattice package in R?
    In this article, we will discuss how to create the boxplots using lattice package in R Programming language. In R programming, Lattice package is a data visualization library and consists of various functions to plot different kind of plots. Using lattice library we can able to plot different plots
    2 min read
  • Strip Plots Using Lattice Package in R
    In general, Strip Plots are used to plot univariate data. It's a 2D plot where on X-Axis the response variables are plotted.  These are alternatives to the histogram or density plot. It is typically used to plot small data sets so here we will be using the iris dataset to implement it. In, R Program
    2 min read
  • Density Plots Using Lattice Package in R
    The density plots are mainly used to visualize the distribution of continuous numeric variables. The densityplot() uses kernel density probability estimate to calculate the density probability of numeric variables. In R Programming, the density plot can be plotted using the densityplot() function wh
    2 min read
  • How to Create Pie Chart Using Plotly in R
    The pie chart is a circular graphical representation of data that is divided into some slices based on the proportion of it present in the dataset.  In R programming this pie chart can be drawn using Plot_ly() function which is present in the Plotly package. In this article, we are going to plot a p
    3 min read
  • How to create 3D Plots and Animations in R using rgl Package
    The R programming language provides a powerful set of tools and packages for creating interactive 3D plots and animations. One such package is RGL. In this article, let us learn How to create 3D plots and animations using the RGL package. Create 3D Plots and Animation in R using RGL Package The RGL
    5 min read
  • Create a Scatter Plot with Multiple Groups using ggplot2 in R
    In this article, we will discuss how to create a scatter plot with multiple groups in R Programming Language. Geoms can be added to the plot to compute various graphical representations of the data in the plot (points, lines, bars). The geom_point() method is used to create scatter plots in R. The g
    2 min read
  • How to Plot in 3D clusters using plotly package
    R-Language is widely used in Data Science, Data Visualization Data Analysis many more, etc. Plotly package is highly rich in plotting various graphs, These graphs/charts are highly interactive and user-friendly. The 3D cluster visualizes the similarity between variables as 3-D spatial relationships.
    2 min read
  • How to Plot 3D Scatter Diagram Using ggplot in R
    The ggplot2 package in R is one of the most popular tools for creating complex and aesthetically pleasing plots. However, ggplot2 is primarily designed for 2D plotting, which presents a challenge when it comes to creating 3D scatter plots. While ggplot2 does not natively support 3D plotting, it can
    4 min read
  • How to Make a Scatter Plot Matrix in R
    A scatterplot matrix is ​​a grid of scatterplots that allows us to see how different pairs of variables are related to each other. We can easily generate a scatterplot matrix using the pairs() function in R programming. In this article, we will walk through the process of creating a scatterplot matr
    6 min read
  • How to Create a Scatterplot in R with Multiple Variables?
    In this article, we will be looking at the way to create a scatter plot with multiple variables in the R programming language.  Using Plot() And Points() Function In Base R: In this approach to create a scatter plot with multiple variables, the user needs to call the plot() function Plot() function:
    3 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