如何平滑折线图?

问题描述

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


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)) +

或连续执行两个命令。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...