如何平滑折线图?
How to smoothen a line chart plot?
我想平滑我的折线图并使用以下代码:
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)) +
或连续两个命令。
我想平滑我的折线图并使用以下代码:
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)) +
或连续两个命令。