0
点赞
收藏
分享

微信扫一扫

【数据可视化应用】绘制峰峦图(附R语言代码)

小暴龙要抱抱 2022-03-11 阅读 64

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参数也是设定为cutgeom_density_ridges()内部全部使用默认参数,并使用了gridges包中theme_ridges()主题。

ggplot(diamonds, aes(x = price, y = cut, fill = cut)) +
	geom_density_ridges() +
	theme_ridges() + 
	theme(legend.position = "none")

图片

2

举报

相关推荐

0 条评论