I am trying to produce a ggplot which shows the period of time that birds spent flying over a site on each day in response to one of four treatments, grouped by Block. There are 6 blocks. Each treatment was administered on a different day over a two-hour time period.
The first issue is that when using facet_grid
, all data points for each Block are grouped on the first date of each Block, rather than being spread across the four days within the Block.
Secondly, despite reading various tutorials, I have been unable to work out how to deal with the time duration (variable = Total.Time) i.e. the minutes and seconds the birds were present. I'd like to use the Total.Time_mins variable to show the total time (minutes and seconds) spent prospecting over the site. The scale is clearly off as the difference between 15 minutes and 2 seconds should be notably larger. The time data in the spreadsheet was entered as HH:MM:SS.
I have attached a copy of the graph, which shows the respective issues:
A sample of the data is provided below in created variables labelled Date, Total.Time_mins and Treatment
Dates <- as.Date(c("0019-10-07", "0019-10-08", "0019-10-09", "0019-10-10", "0019-10-11", "0019-10-12", "0019-10-13", "0019-10-14", "0019-10-14", "0019-10-15","0019-10-16", "0019-10-17"))
Total.Time <- c("0:02:27", "0:00:16","0:00:22", "0:00:03", "0:00:00", "0:00:20", "0:01:32", "0:09:11", "0:00:30", "0:07:26", "0:00:59", "0:14:13")
Treat <- c("Playback", "Control", "Decoys & Playback", "Decoys", "Control", "Decoys", "Playback", "Decoys & Playback", "Decoys", "Playback", "Control", "Decoys & Playback")
Blocks <- c("1","1","1","1","2","2","2","2","3","3","3","3")
Data1 <- data.frame(Dates, Total.Time, Treat, Blocks)
Here is the code I have produced thus far.
[names(Data)
\[1\] "Dates" "Blocks" "Treat" "Observation" "Total.Time"
\[6\] "Time" "Max_Birds" "Landing" "Wind_Speed" "Beaufort_Force_Scale"
\[11\] "Wind_Direction"
# Convert the date information into R's date format. R will automatically treat these dates as numeric in our analyses.
Data$Date <- as.Date(Data$Date, format = "%d/%m/%Y")
# Create GGPlot of time spent prospecting over site
p = ggplot(Data1, aes(Dates, Total.Time, fill=Treat)) + geom_bar(stat = "identity")
p = p + facet_grid(.~ Blocks)
p = p + scale_fill_grey(start=0.8, end=0.0)
p = p + theme(panel.background = element_blank())
p = p + theme(axis.text.x=element_text(size=16, vjust=0.6),
axis.title.x=element_text(face="bold", size=16, vjust=-6),
axis.title.y=element_text(face="bold", size=16),
axis.text.y=element_text(size=16),
legend.text = element_text(size=12),
axis.line=element_line())
p = p + theme(axis.text.x=element_text(size=16, vjust=0.6))
#p = p + scale_x_date(date_labels="%d %b", date_breaks = "4 day", breaks = 4)
p = p + theme(axis.text.x = element_text(face="bold", size=10, angle=90))
p