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.
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:
就我而言,年份将被身高代替。
谢谢!!!
您正在寻找的图表称为山脊线图。尝试一下ggridges https://cran.r-project.org/web/packages/ggridges/vignettes/introduction.html封装有ggplot2
.
时间数据的示例:
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())
结果如下:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)