R:如何:使用gplot和geom_density绘制3d密度图

raf*_*lle 11 3d r density-plot

我正在尝试将多个密度图与叠加层结合起来.ggplot和geom_density可以完成这项任务,但密度相互叠加.这是重叠但不是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")
Run Code Online (Sandbox Code Playgroud)

与此类似的是我正在努力实现的目标: 密度? 与3d叠加

就我而言,年份将由身高代替.

谢谢!!!

Ben*_*ude 8

您正在寻找的图表称为ridgelineplot.试试ggridgesggplot2.

时态数据的示例:

library(viridis)
ggplot(lincoln_weather, aes(x = `Mean Temperature [F]`, y = `Month`, fill = ..x..)) +
  geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01, gradient_lwd = 1.) +
  scale_x_continuous(expand = c(0.01, 0)) +
  scale_y_discrete(expand = c(0.01, 0)) +
  scale_fill_viridis(name = "Temp. [F]", option = "C") +
  labs(title = 'Temperatures in Lincoln NE',
       subtitle = 'Mean temperatures (Fahrenheit) by month for 2016\nData: Original CSV from the Weather Underground') +
  theme_ridges(font_size = 13, grid = TRUE) + theme(axis.title.y = element_blank())
Run Code Online (Sandbox Code Playgroud)

结果如下:

在此输入图像描述


小智 5

我知道这个很旧,但是其他遇到此类问题的人可能会偶然发现这篇文章,所以我想我应该添加一个最近发现的解决方案。有一个新的包刚刚创建来完成这种类型的可视化,它被称为ggjoyggplot2 系统并被设计为与 ggplot2 系统一起使用。

所有信息都可以在这里找到: https: //github.com/clauswilke/ggjoy

希望这能有所帮助!

  • 看来 `ggjoy` 包已被弃用。请参阅:[https://cran.r-project.org/web/packages/ggjoy/vignettes/introduction.html] (2认同)