r - ggridges - 将第一条数据线降低到绘图底部
问题描述
我有一个关于ggplot2
和的问题ggridges
。我想绘制相同的实验 XRD 数据。我怎样才能在不影响第三个图的情况下将第一个数据降低到图的底部(见图)。这是数据
# Data import
data_celestine <- read.table('../Data/celestine.asc')
data_barite <- read.table('../Data/barite.asc')
data_sample <- read.table('../Data/sample.asc')
# Plot
df <- data.frame(
x=data_celestine$V1,
y=c(data_sample$V2, data_celestine$V2, data_barite$V2),
samplename=c(rep('Sample', length(data_celestine$V1)), rep('Celestine',length(data_celestine$V1)), rep('Barite',length(data_celestine$V1))))
library(ggplot2)
library(ggridges)
p <- ggplot(df, aes(x,y, color=samplename))
p + geom_ridgeline(
aes(y=samplename, height=y),
fill=NA, scale=.00004, min_height=-Inf) +
theme_bw()
非常感谢你帮助我。
解决方案
我找到了答案。添加参数add
来expansion
完成这项工作。
# Data import
data_celestine <- read.table('../Data/celestine.ASC')
data_barite <- read.table('../Data/barite.asc')
data_sample <- read.table('../Data/sample.asc')
# Plot
library(ggplot2)
library(ggridges)
df <- data.frame(
x=data_celestine$V1,
y=c(data_sample$V2, data_celestine$V2, data_barite$V2),
sample_name=c(rep('Sample', length(data_celestine$V1)), rep('Celestine',length(data_celestine$V1)), rep('Barite',length(data_celestine$V1))))
p <- ggplot(df, aes(x,y, color=sample_name))
p + geom_ridgeline(
aes(y=sample_name, height=y),
fill=NA, scale=.000045, min_height=-Inf) +
scale_y_discrete(expand = expansion(add = c(0.025, 0.6))) +
theme_bw()
推荐阅读
- batch-file - 在 Windows 10 上使用 Robocopy 的脚本在 W7 上不起作用
- r - 将 ggsave() 纵横比设置为 RStudio 的“缩放”按钮给出的比例?
- javascript - javascript:如何停止播放页面上的所有 youtube 嵌入视频?
- postgresql - 创建包含 Postgis 功能的数据库
- maven - maven 生成 pom.properties 文件添加日期属性
- django - 通道 websocket AsyncJsonWebsocketConsumer 未达到断开连接
- javascript - 如何将嵌套数组中的元素转换为具有名称和值属性的对象数组?
- javascript - 将元素附加到DOM后如何重新加载脚本
- css - 如何在 CSS3 中更改 mat-checkbox 背景颜色?角6
- numpy - 如何理解 np.argwhere 函数?