I have created a barplot using barplot
and then I want to show the linear trend. I use abline
but the linear trend line does not show in the figure. I wonder what the problem is. Thanks.
set.seed(100)
Mydata=rnorm(65)
Year=1950:2014
barplot(Mydata)
fit=lm(Mydata~Year)
abline(fit)
As @G5W points out, fit=lm(Mydata~I(Year-1950))
. But the new problem is that the trend line is too "long". As shown in the second figure, the trend line goes beyond the barplot. Is there any advice?
If you can use ggplot: