R 中的 ggplot 平滑 - 解释

ggplot smoothing in R - interpretation

Count of words over time

我使用以下代码在 R 中创建了以下图:

          ggplot(sentiment, aes(x = year, y = nrc_sent$sentiment)) + 
        geom_smooth(method = "auto") +  # pick a method & fit a model
        scale_x_continuous(breaks = round(seq(min(sentiment$year), max(sentiment$year), by = 2),1))+
        labs(x="", y="")

geom_smooth() using method = 'loess'(在 运行 代码时收到此消息)

其中nrc_sent代表

> nrc_sent
# A tibble: 519 x 3
sentiment state year
<dbl> <chr> <dbl>
1 152. Alabama 2007.
2 107. Alabama 2008.
3 80. Alabama 2009.
4 75. Alabama 2010.
5 173. Alabama 2011.
6 180. Alabama 2012.
7 187. Alabama 2013.
8 167. Alabama 2014.
9 124. Alabama 2015.
10 215. Alabama 2016.
# ... with 509 more rows

我对线周围的阴影区域代表什么感到困惑。我查看了 ggplot 帮助 page,但在我的学术文章中似乎没有任何信息可以用来解释图表代表什么以及阴影区域是什么。如果您对此有任何帮助,我将不胜感激

如果您查看 geom_smooth 的文档: ?geom_smooth ,它指出参数 se 用于控制拟合线周围是否存在置信区间。如果它是 TRUE 那么您将被指示查看 level level 是要使用的置信区间水平,默认值为 0.95。

我猜这也适用于您。真正玩关卡。

ggplot(sentiment, aes(x = year, y = nrc_sent$sentiment)) + 
        geom_smooth(method = "loess", se=TRUE,level=0.95) +  # pick a method & fit a model
        scale_x_continuous(breaks = round(seq(min(sentiment$year), max(sentiment$year), by = 2),1))+
        labs(x="", y="")