- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 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.
> x<-rnorm(10) > x
 -1.14191974 1.11554154 -0.01255755 1.18841175 1.11300329 -0.69925814  -0.88000117 0.67830803 -0.91237446 -1.14223973
> y<-rnorm(10) > y
 -1.69229826 -0.70352587 0.38544874 0.14022473 0.15490539 -0.25938630  0.15608239 0.16090625 0.05822404 0.26972301
> plot(x,y) > segments(x0=-0.23,y0=-0.23,x1=0.23,y1=0.23)
> x<-rpois(10,5) > x
 5 0 2 9 4 5 6 2 2 2
> y<-rpois(10,5) > y
 3 3 6 6 7 5 2 1 3 4
> plot(x,y) > segments(x0=2,y0=2,x1=5,y1=5)
- How to write a long line for the X-label of a scatterplot in R using ggplot2?
- How to create regression model line in a scatterplot created by using ggplot2 in R?
- How to create scatterplot for factor levels in an R data frame?
- How to create facetted scatterplot with scale of X-axis based on the numerical values corresponding to grouping column in R?
- How to create horizontal line for Y variable at median in base R plot?
- How to create a scatterplot between a variable and an equation in R?
- How to create a scatterplot with log10 of dependent 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 horizontal line for a range of values in a plot created by using ggplot2 in R?
- How to create vertical line for X variable at median in base R plot
- How to create a scatterplot with colors as group in R?
- Create scatterplot for two dependent variables and one independent variable in R.
- How to create a scatterplot in R using ggplot2 with transparency of points?
- How to create scatterplot for categories with grey color palette using ggplot2 in R?
- How to create a scatterplot with colors of the group of points in R?