- 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 create a scatterplot in R using ggplot2 with different designs of points?
Scatterplot helps us to identify the linear relationship between two variables and it is the first step of determining a predictive model. Before using any predictive modeling technique we must draw a scatterplot between independent and dependent variables to check what kind of relationship exists between them. A scatterplot generally represented by circular points on the plot area but we can have different types of points such as square, rectangle, diamond, etc. In ggplot2, pch argument of geom_point can help us to create scatterplot with these types of points.
Example
Consider the below data frame −
set.seed(123) x <-rnorm(10,0.5) y <-rpois(10,5) df <-data.frame(x,y) library(ggplot2)
Creating the scatterplot with circular points −
ggplot(df,aes(x,y))+geom_point(pch=16,size=5)
Output
Creating the scatterplot with triangular points
ggplot(df,aes(x,y))+geom_point(pch=17,size=5)
Output
Creating the scatterplot with diamond points −
ggplot(df,aes(x,y))+geom_point(pch=18,size=5)
Output
Creating the scatterplot with square points −
ggplot(df,aes(x,y))+geom_point(pch=15,size=5)
Output
- Related Articles
- 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 create a scatterplot with low intensity of points using ggplot2 in R?
- How to create a scatterplot using ggplot2 with different shape and color of points based on a variable in R?
- How to create a scatterplot with two legends using ggplot2 in R?
- How to create scatterplot with intercept equals to 1 using ggplot2 in R?
- How to change the color of points in a scatterplot using ggplot2 in R?
- How to color scatterplot points based on a threshold using ggplot2 in R?
- How to create scatterplot using ggplot2 without grey background in R?
- How to create a scatterplot with white background and no gridlines using ggplot2 in R?
- How to create scatterplot for categories with grey color palette using ggplot2 in R?
- How to change the default type of points for scatterplot using ggplot2 in R?
- How to create a scatterplot in R with legend position inside the plot area using ggplot2?
- How to change the border color of points in a scatterplot created with ggplot2 in R?
- How to create a point chart with empty points using ggplot2 in R?
