1.数据结构
这里使用base
包中的diamonds
数据集做例子。
# librarylibrary(ggridges) # Ridgeline Plots in ggplot2, CRAN v0.5.2library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics, CRAN v3.3.2 head(diamonds)
2.绘图教程
2.1基础版本
使用price
作为x轴,cut
为y轴,fill
参数也是设定为cut
。geom_density_ridges()
内部全部使用默认参数,并使用了gridges包中theme_ridges()
主题。
ggplot(diamonds, aes(x = price, y = cut, fill = cut)) +geom_density_ridges() +theme_ridges() + theme(legend.position = "none")
2
如果觉得《【数据可视化应用】绘制峰峦图(附R语言代码)》对你有帮助,请点赞、收藏,并留下你的观点哦!