POSIXct and geom_vline

168 views
Skip to first unread message

McCreight

unread,
Jul 3, 2010, 3:00:11 PM7/3/10
to ggplot2
Hi-

I'm still struggling with POSIXct in ggplot, this time with
geom_vline. The results, as you'll see, put the line in the wrong
place or nowhere.


t.start <- as.POSIXct(strptime('1/4/2005/00',"%d/%m/%Y/%H"),tz='MST')
dum.frame <- data.frame(time=as.POSIXct(t.start + (3600*(0:
(1*24))) ,tz='MST'),var1=1:25)
wh.20=which(dum.frame$var1==20)

print(ggplot( dum.frame, aes(x=time,y=var1)) + geom_point() +
geom_vline( data=dum.frame[wh.20,], aes(x=time) ) )

print(ggplot( dum.frame, aes(x=time,y=var1)) + geom_point() +
geom_vline( xintercept=dum.frame$time[wh.20] ) )



Is there a way to make it work?

Thanks,

James

Hadley Wickham

unread,
Jul 3, 2010, 3:05:33 PM7/3/10
to McCreight, ggplot2
Hi James,

You were pretty close. Here are two options that work:


ggplot( dum.frame, aes(x=time,y=var1)) + geom_point() +

geom_vline( data=dum.frame[wh.20,], aes(xintercept=time) )

ggplot( dum.frame, aes(x=time,y=var1)) + geom_point() +

geom_vline( xintercept= as.numeric(dum.frame$time[wh.20] ))

Hadley

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

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages