How to use Base R Programming In R Language

In this approach to make transparent scatterplot points, the user needs to install and import the scales package in the working console of the R and this package here is responsible to adjust the alpha of given data points. Further, the user needs to simply call the plot function with the additional alpha argument with this function and specify the alpha value accordingly as per the requirements to make transparent scatterplot points in the base R programming language.

To install and import the scales package, the user needs to follow the below syntax:

install.packages("scales")                                      
library("scales")  

Example: In this example, we will be plotting an of the given data and will be setting the value of the alpha argument to 0.2 to transparent effect in the plotted scatterplot in the R programming language.

The plot without any transparent effect looks as below:

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:

Transparent Scatterplot Points in Base R and ggplot2

In this article, we are going to see how to make transparent scatterplot points in the R programming language.

Here we will use alpha parameter inside the plot. It is used to modify color transparency, alpha value=1 is by default and if we make the alpha value nearer to zero it will be making the object more transparent and on the other hand, the alpha value nearer to 1 will leading to make the object opaque.

Similar Reads

Method 1: Using Base R Programming

In this approach to make transparent scatterplot points, the user needs to install and import the scales package in the working console of the R and this package here is responsible to adjust the alpha of given data points. Further, the user needs to simply call the plot function with the additional alpha argument with this function and specify the alpha value accordingly as per the requirements to make transparent scatterplot points in the base R programming language....

Method 2: Using ggplot2 Package

...