I have data collected over multiple days, with timestamps that contain information for when food was eaten. Example dataframes:
head(Day3)
==================================================================
Day3.time Day3.Pellet_Count
1 18:05:30 1
2 18:06:03 2
3 18:06:34 3
4 18:06:40 4
5 18:06:52 5
6 18:07:03 6
head(Day4)
==================================================================
Day4.time Day4.Pellet_Count
1 18:00:21 1
2 18:01:34 2
3 18:02:22 3
4 18:03:35 4
5 18:03:54 5
6 18:05:06 6
Given the variability, the timestamps don't line up and therefore aren't matched. I've done a "full join" with merge from all of the data from two of the days, in the following way:
pellets <- merge(Day3, Day4, by = 'time', all=TRUE)
This results in the following:
head(pellets)
==================================================================
pellets.time pellets.Pellet_Count.x pellets.Pellet_Count.y
1 02:40:18 39 NA
2 18:00:21 NA 1
3 18:01:34 NA 2
4 18:02:22 NA 3
5 18:03:35 NA 4
6 18:03:54 NA 5
I would like to plot the Pellet_Count in one line graph from each of the days, but this is making it very difficult to group the data. My approach thus far has been:
pelletday <- ggplot() + geom_line(data=pellets, aes(x=time, y=Pellet_Count.x)) + geom_line(data=pellets, aes(x=time, y=Pellet_Count.y))
But, I get this error:
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
I also would like to be able to merge all days (I oftentime have up to 9 days), and plot it on the same graph.
I believe my goal is to ultimately get the following dataframe output:
==================================================================
pellets.time Pellet_Count Day
1 02:40:18 39 3
2 18:00:21 1 4
3 18:01:34 2 4
4 18:02:22 3 4
5 18:03:35 4 4
6 18:03:54 5 4
and to use this to graph: ggplot(pellets, aes(time, Pellet_Count, group=Day)
Any ideas?