scenarios with `ggplot2` when trying to layer multiple plots with different aesthetics
I'm getting frustrated with I'm working with an scenario when using `ggplot2` to create a combined plot with multiple layers that have different aesthetics. Specifically, I'm trying to overlay a scatter plot on top of a density plot, but the second layer seems to not respect the scales and I end up with misaligned visualizations. Hereβs the code snippet Iβm using: ```r library(ggplot2) # Sample data set.seed(123) data <- data.frame( x = rnorm(100), y = rnorm(100) ) # Scatter plot p <- ggplot(data, aes(x = x, y = y)) + geom_point(alpha = 0.5) + theme_minimal() # Adding density plot p + geom_density_2d(aes(color = ..level..), size = 0.5) ``` When I run this code, I get the following warning: ``` Warning: 'color' is not a valid aesthetic for this geom. ``` The density plot does not seem to overlay correctly with the scatter plot, and the colors are not appearing as I expected. I've also tried adding `scale_color_gradient()` to set the color scale, but it doesn't seem to make any difference. I would appreciate any guidance on how to properly combine these two layers with compatible aesthetics. Is there a best practice for this type of visualization in `ggplot2`, or is there a specific function that I might be missing? For context: I'm using R on Ubuntu. What am I doing wrong? I'm working with R in a Docker container on Debian. Thanks for taking the time to read this!