岭线图2

岭线图又称山脉图,可用来观察一个连续变量在不同组中的分布情况。


安装并载入R包。


install.packages("ggridges")
library(ggridges)
library(ggplot2) # 需安装install.packages("ggplot2")


使用"ggplot2"中数据集diamonds作图。


使用一个连续变量 price和一个分类变量 cut,画出一个“直方图形式”的岭线图:

ggplot(diamonds, aes(x = price, y = cut, fill = cut)) +
  geom_density_ridges(color = "grey", stat = "binline", bins = 20) +
  theme_bw()


▌欢迎关注公众号:R语言和统计
▌课程相关咨询可添加R师妹微信: kefu_rstats
▌邮箱:contact@rstats.cn
▌网站:www.rstats.cn
我们致力于让R语言和统计变得简单!



2023-02-22 16:59
首页    ggplot2    岭线图2