r语言 - 如何平滑折线图?



我想要平滑我的折线图,并有以下代码:


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.

正如评论中指出的那样,在stat_smooth()调用中使用aes(x=date,y=ARIS_TOP)aes(x=date,y=SWI_001):

stat_smooth(aes(x=date,y=ARIS_TOP)) +

stat_smooth(aes(x=date,y=SWI_001)) +

或在一行中同时使用

最新更新