- 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 display the values of two columns of an R data frame separately in a plot?
In general, the scatterplot is used to visualize the relationship between two columns of an R data frame but if we want to display the two columns separately not as a pair then we need to use matplot function. This function will create a plot for all the values in the two columns and represent them by their column number.
Consider the below data frame −
Example
set.seed(222) x<-rnorm(20,2,0.5) y<- rpois(20,2) df<-data.frame(x,y) df
output
x y 1 2.7438785 3 2 1.9990540 4 3 2.6905104 3 4 1.8098932 3 5 2.0920681 1 6 1.8765521 3 7 1.3922195 4 8 2.7807025 2 9 2.2136551 0 10 1.3994882 4 11 2.5262292 0 12 1.3474682 2 13 1.6536962 2 14 2.3013244 4 15 1.9011235 1 16 1.4070627 0 17 0.9972435 1 18 2.0037549 1 19 2.2597452 4 20 1.6268523 2
Creating the plot for all the values in the two columns of data frame df −
matplot(df)
Output
- Related Articles
- How to plot all the values of an R data frame?
- Combine values of two columns separated with hyphen in an R data frame.
- How to plot two columns of a Pandas data frame using points?
- How to create table of two factor columns in an R data frame?
- How to convert two columns of an R data frame to a named vector?
- How to find the minimum and maximum of columns values in an R data frame?
- How to fill the missing values of an R data frame from the mean of columns?
- How to find the class of columns of an R data frame?
- How to create a column in an R data frame that contains the multiplication of two columns?
- How to change the order of columns in an R data frame?
- How to add a prefix to columns of an R data frame?
- How to replace NA values in columns of an R data frame form the mean of that column?
- How to find the sum of every n values in R data frame columns?
- How to remove rows that contains NA values in certain columns of an R data frame?
- How to reorder the columns in an R data frame?

Advertisements