

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 create a line for equal values of x and y in scatterplot in R?
To create a line for equal values of x and y in scatterplot, we can make use of segments function in base R but this can be done after creating the plot with the help of plot function. The segments function has four arguments, x0, y0, x1, and y1, we need to put the same value in x0 and y0 and the same value in x1 and y1 to draw the appropriate line as shown in the below examples.
Example1
> x<-rnorm(10) > x
Output
[1] -1.14191974 1.11554154 -0.01255755 1.18841175 1.11300329 -0.69925814 [7] -0.88000117 0.67830803 -0.91237446 -1.14223973
Example
> y<-rnorm(10) > y
Output
[1] -1.69229826 -0.70352587 0.38544874 0.14022473 0.15490539 -0.25938630 [7] 0.15608239 0.16090625 0.05822404 0.26972301
Example
> plot(x,y) > segments(x0=-0.23,y0=-0.23,x1=0.23,y1=0.23)
Output
Example2
> x<-rpois(10,5) > x
Output
[1] 5 0 2 9 4 5 6 2 2 2
Example
> y<-rpois(10,5) > y
Output
[1] 3 3 6 6 7 5 2 1 3 4
Example
> plot(x,y) > segments(x0=2,y0=2,x1=5,y1=5)
Output
- Related Questions & Answers
- How to write a long line for the X-label of a scatterplot in R using ggplot2?
- How to create horizontal line for Y variable at median in base R plot?
- How to create regression model line in a scatterplot created by using ggplot2 in R?
- How to create vertical line for X variable at median in base R plot
- Find larger of x^y and y^x in C++
- How to create facetted scatterplot with scale of X-axis based on the numerical values corresponding to grouping column in R?
- How to create a scatterplot between a variable and an equation in R?
- How to create a dashed line that passes through Y = 1 in base R?
- How to create scatterplot for factor levels in an R data frame?
- How to create a scatterplot with log10 of dependent variable in R?
- How to display average line for y variable using ggplot2 in R?
- How to create horizontal line for a range of values in a plot created by using ggplot2 in R?
- Create scatterplot for two dependent variables and one independent variable in R.
- How to create a scatterplot with regression line using ggplot2 with 0 intercept and slope equals to 1 in R?
- How to create a random vector for a range of values in R?
Advertisements