问题描述
我想平滑我的折线图并有以下代码:
ggplot7 <- ggplot(rye) + geom_line(aes(x=date,y=ARIS_TOP),group=1,color='blue',alpha=0.5) +
geom_line(aes(x=date,y=SWI_001),group=2,color='darkturquoise',alpha=0.5) +
scale_y_continuous(limits = c(7,27,by = 2 )) +
scale_x_date(labels = date_format('%b'),date_breaks = '2 month') +
ylab('Soil Moisture (%)')+xlab('Date') +
labs(title=('Absolute Soil Moisture')) +
stat_smooth() +
geom_hline(yintercept= c(9,23),size =0.75,color='firebrick',linetype= 'dashed')
ggplot7 + theme_bw(base_family='Playfair',base_size = 15,base_rect_size = 1)
我在网上找到了一些方法,但似乎我无法找到正确的代码。 这是我收到的错误消息:
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
Fehler: stat_smooth requires the following missing aesthetics: x and y
Run `rlang::last_error()` to see where the error occurred.
解决方法
正如评论中所指出的,在您的 aes(x=date,y=ARIS_TOP)
调用中使用 aes(x=date,y=SWI_001)
或 stat_smooth()
:
stat_smooth(aes(x=date,y=ARIS_TOP)) +
或
stat_smooth(aes(x=date,y=SWI_001)) +
或连续执行两个命令。