首页 > 解决方案 > 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()

阴谋

非常感谢你帮助我。

标签: rggplot2ggridges

解决方案


我找到了答案。添加参数addexpansion完成这项工作。

# 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()

阴谋


推荐阅读