Transparent Scatterplot Points in Base R and ggplot2
Last Updated :
16 Apr, 2025
In this article, we will explore how to create transparent scatterplot points in R. We will use the alpha
parameter within the plotting function to control the transparency of the points.
The alpha
value ranges from 0 to 1, where a value closer to 0 makes the points more transparent, and a value closer to 1 makes them more opaque. By adjusting this parameter, we can enhance the visual clarity of overlapping data points in the scatterplot.
Method 1: Using Base R Programming
In this method for creating transparent scatterplot points, we need to install and load the scales
package in R. This package allows us to adjust the alpha (transparency) levels of the data points. To apply transparency, we call the plot()
function and use the alpha
argument.
To install and import the scales package:
install.packages("scales")
library("scales")
Example:
In this example, we will plot a scatter plot of the given data and set the alpha
value to 0.2 to create a transparent effect in the scatterplot using the R.
R
library("scales")
gfg <- data.frame(x = c(1, 2.2, 2, 2, 3, 3,
4.2, 4.1, 5.2, 5.1),
y = c(2, 2, 2.5, 2.1, 3.4,
4.1, 4, 4, 5, 5),
group = as.factor(1:2))
plot(gfg$x, gfg$y, pch = 18, cex = 6,
col = gfg$group)
Output:

Using alpha to create a transparent plot:Â
R
library("scales")
gfg <- data.frame(x = c(1, 2.2, 2, 2, 3, 3,
4.2, 4.1, 5.2, 5.1),
y = c(2, 2, 2.5, 2.1, 3.4,
4.1, 4, 4, 5, 5),
group = as.factor(1:2))
plot(gfg$x,gfg$y, pch = 18, cex = 6,
col = alpha(gfg$group, 0.2))
Output:

Method 2: Using ggplot2 Package
To create transparent scatter plot points using the geom_point()
function, we need to install and load the ggplot2 package in R. This package allows us to create scatter plots and other visualizations. To control transparency, we use the alpha
argument within geom_point()
, where lower values make points more transparent and values closer to 1 make them more opaque.
To install and import the ggplot2 package:
install.packages("ggplot2")
library("ggplot2")
Example:
In this example, we will plot the given data and set the value of the alpha
argument to 0.2 to achieve a transparent effect in the scatterplot using the ggplot2 package in R.
R
library("ggplot2")
gfg <- data.frame(x = c(1, 2.2, 2, 2, 3, 3,
4.2, 4.1, 5.2, 5.1),
y = c(2, 2, 2.5, 2.1, 3.4,
4.1, 4, 4, 5, 5),
group = as.factor(1:2))
ggplot(gfg, aes(x, y, col = group)) +
geom_point(pch = 18,size = 12)
Output:

Using alpha to create a transparent plot:
R
library("ggplot2")
gfg <- data.frame(x = c(1, 2.2, 2, 2, 3, 3, 4.2,
4.1, 5.2, 5.1),
y = c(2, 2, 2.5, 2.1, 3.4, 4.1,
4, 4, 5, 5),
group = as.factor(1:2))
ggplot(gfg, aes(x, y, col = group)) +
geom_point(pch = 18,size = 12, alpha = 0.2)
Output:

Similar Reads
Control Point Border Thickness of ggplot2 Scatterplot in R In this article, we will see how to control Point Border Thickness of ggplot ScatterPlot in R Programming Language. For this, we will be using geom_point() function. Following is brief information about ggplot function, geom_point(). Syntax : geom_point(size, color, fill, shape, stroke) Parameter :
2 min read
Superscript and subscript axis labels in ggplot2 in R In this article, we will see how to use Superscript and Subscript axis labels in ggplot2 in R Programming Language. First we should load ggplot2 package using library() function. To install and load the ggplot2 package, write following command to R Console. # To Install ggplot2 package # (Write thi
3 min read
Set Axis Breaks of ggplot2 Plot in R In this article, we are going to see how to set axis break of ggplot2 plot in R Programming Language. To add axis breaks in ggplot2 plots in R, we use scale_x_break() and scale_y_break() functions. These functions take a vector as a parameter that has breakpoints.  If we need multiple breakpoints w
2 min read
How to Change the Color of Points for ggplot2 Scatterplot Using ColorBrewer in R When visualizing data using scatter plots, coloring the points can help distinguish between categories or highlight certain patterns in the data. In this article, we will explore how to change the color of points in a ggplot2 scatterplot using RColorBrewer in R.Introduction to ColorBrewerRColorBrewe
4 min read
Add Text to ggplot2 Plot in R In this article, we are going to see how to add Text to the ggplot2 plot in R Programming Language. To do this annotate() is used. It is useful for adding small annotations (such as text labels) or if you have your data in vectors, and for some reason don't want to put them in a data frame. Syntax:
2 min read