graphing time data on x and y axis?

30 views
Skip to first unread message

Mike Dylan

unread,
Jan 8, 2013, 11:17:18 AM1/8/13
to ggp...@googlegroups.com

I have a data frame like this:

df

StartTime          EndTime         ThresholdTime       Athlete
1/1/12 02:00     02:10             03:00                      A
1/1/12 03:00     04:10             03:30                      C
1/1/12 01:00     02:00             01:30                     D
1/1/12 05:00     05:10             04:00                     E
1/1/12 06:00     7:10               07:00                    F

I would like to be able to use x axis as StartTime, y axix as EndTime and right side of the vertical axis to be ThresholdTime to draw horizontal line. I like to have a different graph for each Athlete, Is this doable in ggplot2?

Brian Diggs

unread,
Jan 8, 2013, 1:54:13 PM1/8/13
to Mike Dylan, ggplot2
I'm not entirely clear on what you want. However, I wrote a blog post on
working with time-of-day (separate from dates) in ggplot:
http://blog.ggplot2.org/post/29433173749/ that may be helpful.

--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

Mike Dylan

unread,
Jan 8, 2013, 4:02:59 PM1/8/13
to ggp...@googlegroups.com
Hi Brian:
 

Brandon Hurr

unread,
Jan 9, 2013, 8:26:40 AM1/9/13
to Mike Dylan, ggplot2
I think part of the problem is that you don't have you date's properly formated. See this blog post for some help. Once you get your dates in the right format, you're going to have to use the new scales package to get the format and breaks that you're after. Sadly, it's not something I do a lot so we'll need more help. 


Something like: 

yy$Date<-as.POSIXct(yy$Date, format="%Y-%m-%d")

yy$STime<-as.POSIXct(yy$STime, format="%H:%M")
yy$ETime<-as.POSIXct(yy$ETime, format="%H:%M")


ggplot(yy, aes(Date, ETime, group="Team")) + 
geom_jitter() + 
facet_wrap( ~ Team) + 
geom_hline(yintercept=yy$Stime, colour="red", size=2)

#Except it errors out because your data is all the same
#Error in prettyDate(x = x, n = n, min.n = min.n, sep = sep, ...) : 
# range too small for min.n



--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages