我正在尝试将多密度图与覆盖图相结合。ggplot和geom_density可以完成这项工作,但密度是堆叠在一起的。
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")
类似的东西就是我想要实现的:
在我的例子中,年份会被高度所代替。
谢谢!
发布于 2017-07-18 03:39:53
我知道这很久了,但是其他有这种问题的人可能会偶然发现这篇文章,所以我想我应该添加一个最近发现的解决方案。有一个新的包就是为了完成这种类型的可视化而创建的,它被称为ggjoy
,旨在与ggplot2系统一起工作。
所有信息都可以在这里找到:https://github.com/clauswilke/ggjoy
希望这能对你有所帮助!
发布于 2018-04-03 04:58:02
你要找的图表叫做脊线图。尝试使用ggplot2
的ggridges包。
下面是使用时态数据的示例:
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())
结果如下:
发布于 2016-09-11 12:43:54
正如@jlhoward所提到的,使用facet或使用子图可以工作,但这两种方法都不能很好地扩展到大量的组。请考虑使用ecdf图。
如果没有object all.complete中的数据,我就无法重新创建绘图,因此这里有一个简化的示例:
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length)) +
geom_density(aes(group = Species,
colour = Species,
fill = Species),
alpha = 0.2)
对于不止几个小组,我发现ecdf图更容易解释。要制作类似的图:
ggplot(iris, aes(x = Sepal.Length)) +
stat_ecdf(aes(color = Species))
您可以在同一个图上有几十个ecdf图,因为它们只是线,所以它们仍然足够分开以供查看。密度图或直方图可能会过于重叠,如您的示例所示。
这是促使我开始使用ecdf图的博客文章,并提供了有关它们的更多信息:http://allendowney.blogspot.com/2013/08/are-my-data-normal.html
https://stackoverflow.com/questions/25985159
复制相似问题