- 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 with dark points using ggplot2 in R?
To create a scatterplot with low intensity of points using ggplot2, we can follow the below steps −
- First of all, create a data frame.
- Then, create the scatterplot.
- Create the scatterplot with scale_color_hue function for dark points.
Create the data frame
Let's create a data frame as shown below −
x<-sample(1:100,25) y<-sample(1:100,25) Factor<-sample(c("Real","Imaginary"),25,replace=TRUE) df<-data.frame(x,y,Factor) df
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
x y Factor 1 43 50 Imaginary 2 6 52 Imaginary 3 19 60 Real 4 42 24 Real 5 99 66 Imaginary 6 32 69 Real 7 11 91 Imaginary 8 97 93 Imaginary 9 16 99 Real 10 76 7 Real 11 95 89 Imaginary 12 13 4 Imaginary 13 74 49 Imaginary 14 40 94 Real 15 54 47 Imaginary 16 38 15 Real 17 96 74 Real 18 20 72 Imaginary 19 34 23 Real 20 57 87 Imaginary 21 82 2 Real 22 36 59 Imaginary 23 98 67 Real 24 1 98 Real 25 65 62 Real
Create the scatterplot
Use geom_point function of ggplot2 package to create the scatterplot −
x<-sample(1:100,25) y<-sample(1:100,25) Factor<-sample(c("Real","Imaginary"),25,replace=TRUE) df<-data.frame(x,y,Factor) library(ggplot2) ggplot(df,aes(x,y,color=Factor))+geom_point()
Output
Create the scatterplot with dark points
Use scale_color_hue function of ggplot2 package with l argument to create the scatterplot with dark points(the default values for l is 65) −
x<-sample(1:100,25) y<-sample(1:100,25) Factor<-sample(c("Real","Imaginary"),25,replace=TRUE) df<-data.frame(x,y,Factor) library(ggplot2) ggplot(df,aes(x,y,color=Factor))+geom_point()+scale_color_hue(l=50)
Output
- Related Articles
- How to create a scatterplot in R using ggplot2 with transparency of points?
- How to create a scatterplot in R using ggplot2 with different designs of points?
- How to create a scatterplot with low intensity of points using ggplot2 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 create a scatterplot using ggplot2 with different shape and color of points based on a variable 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 change the color of points in a scatterplot using ggplot2 in R?
- How to create scatterplot for categories with grey color palette using ggplot2 in R?
- How to create a scatterplot in R with legend position inside the plot area using ggplot2?
- How to create a point chart with empty points using ggplot2 in R?
- How to change the default type of points for scatterplot using ggplot2 in R?
- How to create regression model line in a scatterplot created by using ggplot2 in R?

Advertisements