Transparent Scatterplot Points in R (2 Examples) | scales & ggplot2 | Decrease Plot Opacity / Alpha

Published: 31 May 2021
on channel: Statistics Globe
906
19

How to decrease the alpha of points in an xy-plot using Base R and the ggplot2 package in the R programming language. More details: https://statisticsglobe.com/transpare...
R code of this video:

data <- data.frame(x = c(1, 1.1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1), # Example data
y = c(1, 1.1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1),
group = as.factor(1:2))

plot(data$x, # Draw non-transparent plot
data$y,
pch = 16,
cex = 5,
col = data$group)

install.packages("scales") # Install scales package
library("scales") # Load scales

plot(data$x, # Draw transparent plot
data$y,
pch = 16,
cex = 5,
col = alpha(data$group, 0.5))

install.packages("ggplot2") # Install ggplot2 package
library("ggplot2") # Load ggplot2

ggplot(data, aes(x, y, col = group)) + # Draw non-transparent plot
geom_point(size = 10)

ggplot(data, aes(x, y, col = group)) + # Draw transparent plot
geom_point(size = 10, alpha = 0.5)

Follow me on Social Media:
Facebook:   / statisticsglobecom  
LinkedIn:   / statisticsglobe  
Patreon:   / statisticsglobe  
Pinterest: https://www.pinterest.de/JoachimSchork
Reddit:   / joachimschork  
Twitter:   / joachimschork  


On this page of the site you can watch the video online Transparent Scatterplot Points in R (2 Examples) | scales & ggplot2 | Decrease Plot Opacity / Alpha with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 31 May 2021, share the link with friends and acquaintances, this video has already been watched 906 times on youtube and it was liked by 19 viewers. Enjoy your viewing!