0

I am trying to learn more and more about rayshader which is a fantastic package.

Based on the code and data below , how can I convert the 2D plots to 3D?

I tried the plot_gg function, but it does not convert the lines and histogram to 3D so, maybe I am missing some steps.

Code + data:

# 3D line plot
df2 = data.frame(supp=rep(c("VC", "OJ"), each=3),
                dose=rep(c("D0.5", "D1", "D2"),2),
                len=c(6.8, 15, 33, 4.2, 10, 29.5))

gg_line = ggplot(data=df2, aes(x=dose, y=len, group=supp)) +
  geom_line()+
  geom_point()
# 3D
plot_gg(gg_line, raytrace = TRUE, width = 4,zoom = 0.60, theta = -45, phi = 30, 
       windowsize = c(1400,866))

df = data.frame(
  sex=factor(rep(c("F", "M"), each=200)),
  weight=round(c(rnorm(200, mean=55, sd=5), rnorm(200, mean=65, sd=5)))
  )

# 3D Histogram with density plot
gg_hist = ggplot(df, aes(x=weight)) + 
 geom_histogram(aes(y=..density..), colour="black", fill="white")+
 geom_density(alpha=.2, fill="#FF6666")

# 3D
plot_gg(gg_hist, raytrace = TRUE, width = 4,zoom = 0.60, theta = -45, phi = 30, 
       windowsize = c(1400,866))
Ed_Gravy
  • 1,841
  • 2
  • 11
  • 34
  • 1
    I'm guessing you have the cran package of Rayshader. You need to get the package from Github: `devtools::install_github("tylermorganwall/rayshader")`. Each of your `plot_gg()` calls worked for me. I do want to point out that when you only feed 2 possible dimensions (the second plot), you won't get any height. – Kat Nov 22 '22 at 01:56
  • Yes, your last sentence is the issue, can you help me wirh adding a `height` dimension to these dummy `df`s and plots? – Ed_Gravy Nov 22 '22 at 04:17
  • 1
    The third dimension or the lift you're looking for is based on either `fill` or `color`. If you choose one color, you get a flat image. If you want to add color to density plots, you may want to look ad `geom_density2d`, `ggridges::geom_density_ridges_gradient`, `geom_bin2d`, `geom_hex` or a heatmap. – Kat Nov 22 '22 at 05:17

0 Answers0