0

I am trying to make box plots on the depth movement of 3 fish. One of the boxplots I want it as hourly bins, with the X axis going from 0-25 hours and the other as monthly bins. How do I do hourly or monthly bins of depth to then make boxplots? Could someone help me out, please?

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

1 Answers1

0

The geom_boxplot() requires you to define something like aes(x=hourly, y=depth) in your ggplot layer, where hourly should be a factor whose unique values are the hourly bins. So you are better off to define hourly as a separate variable in your data set and then use that in your ggplot layer. I guess you can define the hourly variable in reference to the Time variable. You could also use facet_grid() to show each Month and Year in your plot (if you have multiple Years and multiple Months within a year).

Isabella Ghement
  • 715
  • 6
  • 14