如何使用 R 创建时间序列螺旋图

How to create a time series spiral graph using R

我想创建一个时间序列,它在视觉上被描绘成像这样的螺旋图。我希望滴答以月而不是小时为单位。每个螺旋将代表年而不是天。我想选择将主要报价分成四个小报价(以周表示)或没有小报价,只有几个月的主要报价。

Time-Spiral Graph

我已经包含了一个模拟数据样本。每日温度均值可以分为四个箱(以周表示)。

Year    Month   Day Temperature
1993    January 1   9
1993    January 2   6
1993    January 3   6
1993    January 4   5
1993    January 5   5
1993    January 6   5
1993    January 7   8
1993    January 8   9
1993    January 9   6
1993    January 10  5
1993    January 11  7
1993    January 12  10
1993    January 13  7
1993    January 14  10
1993    January 15  5
1993    January 16  5
1993    January 17  7
1993    January 18  7
1993    January 19  10
1993    January 20  8
1993    January 21  9
1993    January 22  8
1993    January 23  9
1993    January 24  9
1993    January 25  5
1993    January 26  6
1993    January 27  7
1993    January 28  6
1993    January 29  8
1993    January 30  8
1993    January 31  10
1993    February    1   8
1993    February    2   9
1993    February    3   9
1993    February    4   6
1993    February    5   5
1993    February    6   9
1993    February    7   8
1993    February    8   10
1993    February    9   9
1993    February    10  6
1993    February    11  6
1993    February    12  9
1993    February    13  8
1993    February    14  6
1993    February    15  6
1993    February    16  9
1993    February    17  10
1993    February    18  5
1993    February    19  7
1993    February    20  6
1993    February    21  8
1993    February    22  9
1993    February    23  5
1993    February    24  10
1993    February    25  10
1993    February    26  8
1993    February    27  10
1993    February    28  9
1993    March   1   10
1993    March   2   9
1993    March   3   9
1993    March   4   6
1993    March   5   7
1993    March   6   6
1993    March   7   5
1993    March   8   10
1993    March   9   9
1993    March   10  8
1993    March   11  9
1993    March   12  7
1993    March   13  7
1993    March   14  6
1993    March   15  6
1993    March   16  9
1993    March   17  7
1993    March   18  6
1993    March   19  10
1993    March   20  7
1993    March   21  6
1993    March   22  6
1993    March   23  10
1993    March   24  9
1993    March   25  8
1993    March   26  6
1993    March   27  5
1993    March   28  5
1993    March   29  10
1993    March   30  7
1993    March   31  8
1993    April   1   6
1993    April   2   7
1993    April   3   10
1993    April   4   7
1993    April   5   8
1993    April   6   5
1993    April   7   7
1993    April   8   5
1993    April   9   10
1993    April   10  7
1993    April   11  6
1993    April   12  9
1993    April   13  10
1993    April   14  10
1993    April   15  6
1993    April   16  5

有一个线程显示了实现此目的所需的代码 ();但是,我很难理解代码并对其进行修改以适合我的目的。我希望有人可以指出正确的方向或帮助我自定义代码。

谢谢!!

正如@42 所说,听起来您还需要进行一些其他预处理,以便为您想要的数据做好准备。

在 ggplot 中,这是我会采用的方法。首先将您的数据打印为条形图。然后添加一个上升的基线。最后用coord_polar绕一个年轮。

sample <- data.frame(date = seq.Date(from = as.Date("1993-01-01"), to = as.Date("1996-12-31"), by = 1),
                     day_num = 1:1461,
                     temp = rnorm(1461, 10, 2))

# as normal bar
ggplot(sample, aes(date, temp, fill = temp)) + 
  geom_col() +
  scale_fill_viridis_c() + theme_minimal()
  # or use the fill pattern below to replicate OP picture:
  # scale_fill_gradient2(low="green", mid="yellow", high="red", midpoint=10)

# as ascending bar
ggplot(sample, aes(date, 0.01*day_num + temp/2, 
                   height = temp, fill = temp)) + 
  geom_tile() +
  scale_fill_viridis_c() + theme_minimal()

# as spiral
ggplot(sample, aes(day_num %% 365, 
               0.05*day_num + temp/2, height = temp, fill = temp)) + 
  geom_tile() + 
  scale_y_continuous(limits = c(-20, NA)) +
  scale_x_continuous(breaks = 30*0:11, minor_breaks = NULL, labels = month.abb) +
  coord_polar() + 
  scale_fill_viridis_c() + theme_minimal()