Let’s say we want to create a scatterplot of two variables with many observations (\(10^4\)).

# Sample many values from two independent standard normal distributions.
set.seed(1)
x <- rnorm(10 ^ 4)
y <- rnorm(10 ^ 4)

A regular scatterplot looks like this.

plot(x, y)

With solid points, it’s even worse.

plot(x, y, pch = 19)

But if we set the alpha-transparency of the color to some value much smaller than 1, we automatically get a density-like scatterplot, where the darkness of an area indicates the density (i.e., more observations).

plot(x, y, pch = 19, col = adjustcolor("black", alpha.f = .05))

Finding a good value for alpha.f may need some tweaking. See ?adjustcolor for more details.