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

Veröffentlicht am: 31 Mai 2021
auf dem Kanal: 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  


Auf dieser Seite können Sie das Online-Video Transparent Scatterplot Points in R (2 Examples) | scales & ggplot2 | Decrease Plot Opacity / Alpha mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Statistics Globe 31 Mai 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 906 Mal angesehen und es wurde von 19 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!