- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 add an extra point to scatterplot using ggplot2 in R?
To add an extra point to scatterplot using ggplot2, we can still use geom_point function. We just need to use aes function for quoting with new values for the variables, also we can change the color of this point using colour argument. The display of an extra point will help us to distinguish between a threshold/new value and remaining values.
Consider the below data frame −
Example
x<-rpois(20,5) y<-rpois(20,5) df<-data.frame(x,y) df
Output
x y 1 4 7 2 3 7 3 4 4 4 8 7 5 4 2 6 0 6 7 5 2 8 3 6 9 0 8 10 4 9 11 4 3 12 10 7 13 4 3 14 1 6 15 1 1 16 5 5 17 1 2 18 4 7 19 4 3 20 4 3
Loading ggplot2 package and creating a scatterplot between x and y −
Example
library(ggplot2) ggplot(df,aes(x,y))+geom_point()
Output
Adding a new point to the above plot −
Example
ggplot(df,aes(x,y))+geom_point()+geom_point(aes(x=2,y=2),colour="red")
Output
- Related Articles
- How to create scatterplot using ggplot2 without grey background in R?
- How to create scatterplot with intercept equals to 1 using ggplot2 in R?
- 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 in R using ggplot2 with transparency of points?
- How to color scatterplot points based on a threshold using ggplot2 in R?
- How to change the color of points in a scatterplot using ggplot2 in R?
- How to create a scatterplot in R using ggplot2 with different designs of points?
- How to change the default type of points for scatterplot using ggplot2 in R?
- How to create scatterplot for categories with grey color palette using ggplot2 in R?
- How to create a scatterplot with low intensity of points using ggplot2 in R?
- How to create regression model line in a scatterplot created by using ggplot2 in R?
- How to add a vertical line with some value on a scatterplot created by ggplot2 in R?
- How to reverse the X-axis labels of scatterplot created by using ggplot2 in R?
- How to change the color of points for ggplot2 scatterplot using color brewer in R?

Advertisements