R语言作图——Ridgeline plot(山脊图)
Posted 生信了
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R语言作图——Ridgeline plot(山脊图)相关的知识,希望对你有一定的参考价值。
原创:黄小仙
今天给大家介绍一下Ridgeline plot(山脊图)的画法。
作图数据如下:

Step1. 绘图数据的准备
首先要把你想要绘图的数据调整成R语言可以识别的格式,建议大家在excel中保存成csv格式。
Step2. 绘图数据的读取
data<-read.csv(“your file path”, header = T)
#注释:header=T表示数据中的第一行是列名,如果没有列名就用header=F
Step3. 绘图所需package的安装、调用
library(reshape2)
library(ggplot2)
library(ggridges)
# 注释:package使用之前需要调用
# 今天要用到geom_density_ridges()函数需要调用ggridges包
# 直接用install.packages(ggridges)可以安装
Step4. 绘图
ggplot(data_melt, aes(x = value , y = variable , fill = variable)) +
geom_density_ridges() +
theme_ridges() +
theme(legend.position = "none")

##调整透明度
ggplot(data_melt, aes(x = value , y = variable , fill = variable)) +
geom_density_ridges(alpha = 0.5) +
theme_ridges() +
theme(legend.position = "none")


##更改顺序
level<-levels(data_melt$variable)
data_melt$variable<-factor(data_melt$variable, levels = rev(level))
ggplot(data_melt, aes(x = value , y = variable , fill = variable)) +
geom_density_ridges(alpha = 0.5) +
theme_ridges() +
theme(legend.position = "none")



##更改线条形状
ggplot(data_melt, aes(x = value , y = variable , fill = variable)) +
geom_density_ridges(alpha = 0.5, stat="binline", bins=20) +
theme_ridges() +
theme(legend.position = "none")
以上是关于R语言作图——Ridgeline plot(山脊图)的主要内容,如果未能解决你的问题,请参考以下文章
R语言ggplot2可视化分面图(faceting)可视化分面山脊图(facetted ridgeline plot with facet_wrap)
R语言ggplot2可视化使用ggridges包可视化山脊图(Ridgeline Plots):山脊图(Ridgeline Plots)应用场景受试者口服茶碱的之后观察茶碱的浓度变化的山脊图
seaborn使用FacetGrid函数可视化山脊图(Ridgeline Plot with Seaborn)
ggplot2可视化分面图(faceting)可视化分面山脊图(facetted ridgeline plot with facet_wrap)并自定义分面图标题框(title box)的背景色