如果您缩放/扩展您的 x/y 轴,您可以减少“差距”。以下是 gapminder 数据集的示例:
## No 'expand'
library(ggplot2)
library(ggridges)
data_url = 'https://raw.githubusercontent.com/resbaz/r-novice-gapminder-files/master/data/gapminder-FiveYearData.csv'
gapminder = read.csv(data_url)
ggplot(gapminder, aes(y=as.factor(year),
x=lifeExp)) +
geom_density_ridges() +
theme(axis.text=element_text(size=20))
## With 'expand'
library(ggplot2)
library(ggridges)
data_url = 'https://raw.githubusercontent.com/resbaz/r-novice-gapminder-files/master/data/gapminder-FiveYearData.csv'
gapminder = read.csv(data_url)
ggplot(gapminder, aes(y=as.factor(year),
x=lifeExp)) +
geom_density_ridges() +
scale_y_discrete(expand = c(0.01, 0)) +
scale_x_continuous(expand = c(0, 0))+
theme(axis.text=element_text(size=20))
所以,对于你的问题,这样的事情应该是一个很好的解决方案:
# 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) +
scale_y_discrete(expand = c(0.01, 0)) +
theme_bw()
- 如果您需要进一步的故障排除帮助,发布一些实际数据会很有帮助。