specify legend position with Date axis

902 views
Skip to first unread message

jakebe...@gmail.com

unread,
Aug 21, 2013, 11:15:28 AM8/21/13
to ggp...@googlegroups.com
I am trying to locate a legend in the upper left corner of a plot.  The x-axis is Date data.  The legend position can be specified using opts(legend.position=c(x,y)), but I'm not sure how to reference Date class information for the x-position.  Below is an example where I converted the Date to numeric, but it fails.
 
df <- data.frame(dates = as.Date(c('2012-05-01', '2012-06-01', '2012-07-01')),
        y = c(1,2,3), groups = factor(c('A', 'B', 'C')))

ggplot(df, aes(dates, y)) + geom_point(aes(shape = groups)) +
  opts(legend.position = c(as.numeric(as.Date('2012-05-01')), 2.75))
 
> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)
ggplot2_0.8.9
 
thanks
Jake

Ito, Kaori (Groton)

unread,
Aug 21, 2013, 1:38:25 PM8/21/13
to jakebe...@gmail.com, ggp...@googlegroups.com

I am guessing you are trying to do this?

 

ggplot(df, aes(dates, y)) + geom_point(aes(shape = groups)) +

   opts(legend.position = c(0.1, 0.85))

 

The range for the legend position within a plot is 0-1.

--Kaori

--
--
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
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages