- 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 create a scatterplot between a variable and an equation in R?
To create a scatterplot between a variable and an equation in R, we can follow the below steps −
- First of all, create a vector
- Then, create the equation and store it in an object.
- After that, use plot function to create the plot between vector and equation object
Create the vector
Let’s create a vector as shown below −
x<-sample(1:10,20,replace=TRUE) x
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
[1] 6 9 1 7 3 6 6 2 7 6 1 2 6 7 7 10 3 3 1 1
Create the equation
Let’s create an equation and save it in an object −
y<-1+(1/3.5)*(1/x) y
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
[1] 1.047619 1.031746 1.285714 1.040816 1.095238 1.047619 1.047619 1.142857 [9] 1.040816 1.047619 1.285714 1.142857 1.047619 1.040816 1.040816 1.028571 [17] 1.095238 1.095238 1.285714 1.285714
Create the plot between vector and equation
Using plot function to create the plot between vector x and equation y −
x<-sample(1:10,20,replace=TRUE) y<-1+(1/3.5)*(1/x) plot(x,y)
Output
- Related Articles
- How to create a scatterplot with log10 of dependent variable in R?
- How to create a scatterplot with larger distance between facets in R?
- How to create a scatterplot using ggplot2 with different shape and color of points based on a variable in R?
- Create scatterplot for two dependent variables and one independent variable in R.
- How to create an ordinal variable in R?
- How to create a scatterplot with colors as group in R?
- How to create a dummy variable in R?
- How to create scatterplot for factor levels in an R data frame?
- How to create a scatterplot with two legends using ggplot2 in R?
- How to create a scatterplot with dark points using ggplot2 in R?
- How to create a scatterplot with white background and no gridlines using ggplot2 in R?
- How to create a scatterplot in R using ggplot2 with transparency of points?
- How to create a line for equal values of x and y in scatterplot in R?
- How to create a lagged variable in R for groups?
- How to create a frequency column for categorical variable in an R data frame?

Advertisements