1.数据结构
这里使用base
包中的diamonds
数据集做例子。
# library
library(ggridges) # Ridgeline Plots in 'ggplot2', CRAN v0.5.2
library(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")