how can i draw a point density

Hi @All.
I get problem when using ggplot2 to draw a point geom adding a density on it like below:
image
how can i draw the plot like above picture.
can anyone help me ?

Can you supply some data and code to show us what you have tried so far?

The plot looks like a normal scatter plot, with some transparency (alpha) for the dot-geoms. Here are two possible solutions:

library(ggplot2)
library(dplyr)
data("diamonds")
diamonds <- filter(diamonds, x > 3 & x < 12, y > 5 & y < 12, z > 3 & z < 5)

ggplot(diamonds, aes(x, z)) + geom_point(alpha = .01, shape = 16)


ggplot(diamonds, aes(x, z)) + geom_density_2d_filled()

Created on 2020-11-02 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.