I want to overlay two ggplot2
plots with alpha channels in a way that the resulting image shows both datasets. This is my test data:
data = read
You should plot both densities on the same scale:
ggplot(rbind(data.frame(data, group="a"), data.frame(data2, group="b")),
aes(x=x,y=y)) +
stat_density2d(geom="tile", aes(fill = group, alpha=..density..),
contour=FALSE) +
scale_fill_manual(values=c("a"="#FF0000", "b"="#00FF00")) +
geom_point() +
theme_minimal() +
xlim(-3.3, 3.3) + ylim(-3.3, 3.3) +
coord_cartesian(xlim = c(-3.2, 3.2), ylim = c(-3.2, 3.2))
Otherwise you display a distorted picture of your data.