无法在条形图中添加线性回归线

Fail to add linear regression line in barplot

我有一些关于不同时间段的温度百分比的数据,我想创建一个条形图来显示这些百分比,然后添加一条线性回归线来显示趋势。虽然我设法得到了第一张图,但我没有添加直线线性回归线

基本上我尝试用这些 tx_1 数据制作条形图

tx_1<-c(0.055,0.051,0.057,0.049,0.061,0.045)

mypath<-file.path("C:\tx5\1.jpeg")
jpeg(file = mypath,width = 1200, height = 600)
plot.dim<-barplot(get(name),
                  space= 2,
                  ylim=c(0,0.15),
                  main = "Percentage of days when Tmax < 5th percentile",
                  xlab = "Time Periods",
                  ylab = "Percentage",
                  names.arg = c("1975-1984", "1985-1990", "1991-1996", "1997-2002", "2003-2008", "2009-2014"),
                  col = "darkred",
                  horiz = FALSE)
dev.off()

我也尝试过使用 ggplot,但没有成功

这里我包括了一条连接每个观测值的线和一条整体最佳线性拟合线。希望这有帮助。

library(tidyverse)

year <- tribble(~ Year,~ Percent,
        94,0.055,
        95,0.051,
        96,0.057,
        97,0.049,
        98,0.061,
        99,0.045)

ggplot(year,aes(Year,Percent)) + 
  geom_bar(stat = "identity") + 
  geom_line() + 
  geom_smooth(method = "lm",se = F)