Search code examples
r3ddensity-plot

R: How to : 3d Density plot with gplot and geom_density


I'm trying to combine multiple density plots with overlay. ggplot and geom_density do the job, but the densities are stacked on top of each other.This is overlaid but not 3d

ggplot(all.complete, aes(x=humid_temp)) +  
  geom_density(aes(group=height, colour=height, fill=height.f, alpha=0.1)) + 
  guides(fill = guide_legend(override.aes = list(colour = NULL))) +
  labs(main="Temperature by Height", x="Temperature", y="Density")

Something similar to this is what I'm trying to achieve: Density? with 3d overlay

In my case, the years would be substituted by height.

Thanks!!!


Solution

  • I know this old, but other people with this kind of issue may stumble upon this post, so I thought I'd add a recently discovered solution. There is a new package that was just created to do exactly this type of visualization and it is called ggjoy and is designed to work with the ggplot2 system.

    All of the info can be found here: https://github.com/clauswilke/ggjoy

    Hope this can be of help!