(1)代码:

library(tidyverse)

Utilities %>%
  ggplot(aes(x = as.Date(paste(year, month, '01'), format = '%Y %b %d'), y = gas)) +
  geom_point() +
  labs(title = 'Gas Usage over Time', x = 'Date', y = 'Gas Usage (ccf)')

结果:

Gas Usage over Time

(2)代码:

Utilities %>%
  ggplot(aes(x = as.Date(paste(year, month, '01'), format = '%Y %b %d'), y = gas, color = month)) +
  geom_line() +
  geom_point() +
  labs(title = 'Gas Usage over Time by Month', x = 'Date', y = 'Gas Usage (ccf)', color = 'Month')

结果:

Gas Usage over Time by Month

(3)代码:

Utilities %>%
  ggplot(aes(x = factor(month), y = gas, fill = factor(month))) +
  geom_boxplot() +
  labs(title = 'Gas Usage by Month', x = 'Month', y = 'Gas Usage (ccf)', fill = 'Month')

结果:

Gas Usage by Month

箱线图显示,冬季(12月至2月)和夏季(6月至8月)的气体使用量变化最大。

(4)我们看到了季节性模型(冬季和夏季使用更多气体)和时间趋势模型(在2008年至2010年期间,气体使用量呈上升趋势)。平面图可以帮助我们得出结论。

分析家庭天然气使用趋势:时间序列和箱线图

原文地址: https://www.cveoy.top/t/topic/n86N 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录