0
Date_Time           Temp...C.   Anglers.Names           Water.Body
7/17/2016 8:05:00   24          Jones & Bishop          Lake 1
7/17/2016 9:05:00   25          Jones & Bishop          Lake 1
7/17/2016 10:05:00  26          Jones & Bishop          Lake 1
8/15/2016 8:00:00   26          Smith & Nelson          Lake 2
8/15/2016 9:00:00   26          Smith & Nelson          Lake 2
8/15/2016 10:00:00  27          Smith & Nelson          Lake 2
9/12/2016 8:02:00   25          Militello & Culberson   Lake 3
9/12/2016 11:02:00  26          Militello & Culberson   Lake 3
9/12/2016 14:02:00  26          Militello & Culberson   Lake 3

I have a dataset from a bass live well study where I monitored temperatures in angler's live wells by placing a temp logger in their live wells throughout a tournament day. My question is, is there a way to plot the temperature over time, faceted by the water body and then color coded by the unique angler's name. I'm not sure if the quickest way is to subset out by water body (I have 14 water bodies that I worked), creating 14 new individual datasets, make a plot for that individual water body, and then once I'm done arrange them using something like grid.arrange. When trying to make a single faceted plot for all water bodies, the problem I'm trying to work around is getting the x-axis limits to just be a standard range of hours, regardless of date (for me on my real data probably something like 7 AM - 3 PM since that's about how long most tournaments lasted). But since the study occurred over multiple months, R wants to use the entire 3 months as the x-axis limits.

LivewellTemp <- ggplot(HOBO.Data, aes(Date_Time, Temp...C.,colour=Anglers.Names))+
facet_wrap(~Water.Body)+
geom_line(linetype=2)

enter image description here

Jared
  • 85
  • 2
  • 11
  • Perhaps setting x limits is what you're after? http://stackoverflow.com/questions/3606697/how-to-set-limits-for-axes-in-ggplot2-r-plots – J.Con Oct 13 '16 at 21:52
  • Can you provide your code? – J.Con Oct 13 '16 at 22:00
  • This is just very basic code for the plot. I haven't dove deep into how to plot just by just a standard hour range, so I have done nothing editing the x-axis limits. But as you'll see for the fake data set I provided, the plot will come out with the x-axis from 7/17 to 9/12, and that doesn't work since each tournament occurred on a single day only. – Jared Oct 13 '16 at 22:09
  • And just to note in my real data, I have 14 tournaments (so 14 water bodies), and there are multiple anglers per tournament (~10 per tournament). So, the plot I want is a 14 pane faceted plot with ~10 line graphs per pane, over a standardized hourly time range on the x-axis (like I mentioned before something like 7 am - 3 pm). – Jared Oct 13 '16 at 22:12
  • I get `geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?` Are you using the exact fake data you have provided here? – J.Con Oct 13 '16 at 22:15
  • I didn't use the exact fake data....sorry looking at it you would get that error because in my fake data there is only one angling team per water body. So, in my example code you would have to throw out `colour=Anglers.Names`. Color coding is not part of my problem, so it is not necessary in the example anyways. – Jared Oct 13 '16 at 22:32

1 Answers1

1

Is this what you're after?

LivewellTemp <- ggplot(HOBO.Data, aes(Date_Time, Temp...C.,colour=Anglers.Names))+ facet_wrap(~Water.Body)+geom_line(linetype=2)+ scale_x_discrete(labels=c("7am", "8am", "9am", "10am", "11am", "12pm", "1pm", "2pm", "3pm"))

J.Con
  • 4,101
  • 4
  • 36
  • 64
  • No I still want a continuous x-axis. I just know if there is a way for R to recognize that each facet (so each water body) has different limits (i.e. month/day/time) but still plot all the data over standardized hourly x-axis. – Jared Oct 13 '16 at 22:37
  • I'm sorry I don't understand. Can you provide an example of what you want? – J.Con Oct 13 '16 at 22:40
  • Edited my question. That is the plot I get with my real data. As you can see, it's faceted by the water body (i.e. the lake in which the tournament took place), but you see what I mean with the x-axis. Every tournament took place on a single day, over the course of x number of hours, and the entire sample of data is over 3 month period (from July to September). I want to set the x-axis to be an hourly range that encompasses all the data from every tournament and ignore the month/date aspect of it. You see how the data is scrunched into the month, date and time it actually occurred. – Jared Oct 13 '16 at 23:21
  • Okay, now I understand. Can't you just split the Date_Time column into 2 and plot by time only? To do this quickly you can use the `text to columns` function in Excel, assuming it is in an Excel spreadsheet. – J.Con Oct 13 '16 at 23:30
  • 1
    Or using R `library(reshape2)` `HOBO.data=transform(HOBO.data,Date_Time=colsplit(Date_Time, pattern="\\ ",names=c('Date', 'Time')))` – J.Con Oct 13 '16 at 23:36
  • Only problem is if I change the date and time to two columns in excel, and bring the data back in R, both those variables are factors. I think because I have some NAs in both those columns. Is there a way in R to change a time in factor format to an actual time, without having a date associated with it? – Jared Oct 13 '16 at 23:47
  • 1
    Did you try the second comment using `reshape2`? – J.Con Oct 13 '16 at 23:51
  • 1
    Thanks for your help @J.Con. I ended up using this truncate approach after doing some more investigation to my problem.....http://stackoverflow.com/questions/7655514/how-do-i-plot-only-the-time-portion-of-a-timestamp-including-a-date – Jared Oct 14 '16 at 13:21