【问题标题】:Hourly and monthly boxplot for depth data in RR中深度数据的每小时和每月箱线图
【发布时间】:2018-03-17 20:58:49
【问题描述】:

我正在尝试制作 3 条鱼的深度运动的箱线图。我希望将其中一个箱线图作为每小时的箱子,X 轴从 0-25 小时开始,另一个作为每月的箱子。我如何做每小时或每月的深度箱然后制作箱线图?有人可以帮帮我吗?

head(tagdataRaw2)
     transmitter    ID det_Time  detection_time_ast station sensor_value sensor_unit             species  Easting Northing sp_code    Sp_ID
1 A69-9002-10979 10979 19:32:20 2016-06-26 15:32:20     252       9.0959           m Megalops atlanticus 290481.2  2028719      MA MA-10979
2 A69-9002-10979 10979 19:54:12 2016-06-26 15:54:12     252       1.5159           m Megalops atlanticus 290481.2  2028719      MA MA-10979
3 A69-9002-10979 10979 19:58:31 2016-06-26 15:58:31     247      -0.3033           m Megalops atlanticus 290669.4  2028720      MA MA-10979
4 A69-9002-10979 10979 20:11:58 2016-06-26 16:11:58     252       8.4895           m Megalops atlanticus 290481.2  2028719      MA MA-10979
5 A69-9002-10979 10979 20:15:41 2016-06-26 16:15:41     248       2.4255           m Megalops atlanticus 290291.9  2028713      MA MA-10979
6 A69-9002-10979 10979 20:30:53 2016-06-26 16:30:53     248       4.2447           m Megalops atlanticus 290291.9  2028713      MA MA-10979
        Date     Time dayNight  Dawn  Dusk            datetime   depth    Month
1 2016-06-26 15:32:20      Day Other Other 2016-06-26 15:32:20  9.0959 Jun 2016
2 2016-06-26 15:54:12      Day Other Other 2016-06-26 15:54:12  1.5159 Jun 2016
3 2016-06-26 15:58:31      Day Other Other 2016-06-26 15:58:31 -0.3033 Jun 2016
4 2016-06-26 16:11:58      Day Other Other 2016-06-26 16:11:58  8.4895 Jun 2016
5 2016-06-26 16:15:41      Day Other Other 2016-06-26 16:15:41  2.4255 Jun 2016
6 2016-06-26 16:30:53      Day Other Other 2016-06-26 16:30:53  4.2447 Jun 2016


bplotmt<-ggplot(tagdataRaw2, aes(datetime, depth)) + 
          geom_boxplot() +
          facet_wrap(~Sp_ID, labeller = label_parsed) +
          scale_x_datetime(name="Date", date_breaks="1 months", labels=date_format(format="%b-%Y"))+
          ylab("Depth (m)") +
          ggtitle("Vertical monthly distribution of Atlantic tarpon") +
          scale_y_reverse() 
bplotmt

【问题讨论】:

    标签: r ggplot2 time-series boxplot binning


    【解决方案1】:

    geom_boxplot() 要求您在 ggplot 层中定义类似 aes(x=hourly, y=depth) 的内容,其中 hourly 应该是一个因子,其唯一值是每小时的 bin。所以你最好在你的数据集中将每小时定义为一个单独的变量,然后在你的 ggplot 层中使用它。我想您可以参考 Time 变量来定义每小时变量。您还可以使用 facet_grid() 在绘图中显示每个月和年(如果一年中有多个年和多个月)。

    【讨论】:

    猜你喜欢
    • 2021-05-21
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 2021-09-29
    • 1970-01-01
    • 2021-06-19
    相关资源
    最近更新 更多