我想将几个geom_line()绘图堆叠在另一个上方。但是它们与更改的数据一起出现。
这里是一个例子:
# make 3 data.frame with some random data
x <- seq(5, 15, length = 1000)
data1 <- data.frame(x = x, y = dnorm(x, mean = 10, sd = 3), sample = "1")
data2 <- data.frame(x = x, y = dnorm(x, mean = 7.5, sd = 3), sample = "2")
data3 <- data.frame(x = x, y = dnorm(x, mean = 12.5, sd = 1), sample = "3")
# bind data
data <- bind_rows(data1, data2, data3)
# plot data without stacking
plot.data <- data %>% ggplot(mapping = aes(x = x, y = y, color = sample)) + geom_line()
# plot data with stacking
plot.data <- data %>% ggplot(mapping = aes(x = x, y = y, color = sample)) + geom_line(position = position_stack(vjust = 1, reverse = T))
没有堆叠的地块看起来像这样:
具有堆叠的图看起来像这样:
因此,似乎position_stack对数据求和,而不是将它们移位到某个恒定值,我认为这不是geom_line的预期行为。您能否建议如何使地块仅在另一地块上移动?