【发布时间】:2019-08-20 04:00:28
【问题描述】:
我想在堆叠的 bar_plots 上画一条线(或做点)。由于我没有可以参考的真实数据点(只有分散的值而不是它们的总和)我不知道如何添加这样的行。代码产生了这个情节:
我想添加这条黑线(我的真实数据不是线性的):
library(tidyverse)
##Create some fake data
data3 <- tibble(
year = 1991:2020,
One = c(31:60),
Two = c(21:50),
Three = c(11:40)
)
##Gather the variables to create a long dataset
new_data3 <- data3 %>%
gather(model, value, -year)
##plot the data
ggplot(new_data3, aes(x = year, y = value, fill=model)) +
geom_bar(stat = "identity",position = "stack")
【问题讨论】: