Can anyone think of a way to add, to a 2D scatterplot, a third dimension that houses distinct distributions for Y|X=120, Y|X=140, and Y|X=160? I'm trying to include theoretical standard normals for starters (but would eventually like to include the empirical distributions).
For reference, here's a ggplot2
depiction of the 2D scatterplot
df <- data.frame(x = c(replicate(5, 120), replicate(7, 140), replicate(6, 160)),
y = c(c(79, 84, 90, 94, 98), c(80, 93, 95, 103, 108, 113, 115),
c(102, 107, 110, 116, 118, 125)))
library(dplyr)
df <- df %>% group_by(x) %>% mutate(gp.mn = mean(y))
library(ggplot2)
( ggplot(df, aes(x = x)) + geom_point(aes(y = y)) + geom_line(aes(y = gp.mn)))
I'm essentially trying to replicate an image I created in .tpx:
I'm not tied to any particular 3D package, but plot3Drgl
can be used to generate a 2D plot similar to the one above:
library(plot3Drgl)
scatter2Drgl(df$x, df$y, xlab = "x", ylab = "y")
scatter2Drgl(df$x, df$gp.mn, type = "l", add = TRUE, lwd = 4)
My hope was to use the 2D plot as a building block for a pseudo-3D rgl
plot, however, incorporating the distributions into a third dimension (rgl
or otherwise) is eluding me. Any thoughts?