[R] ggplot2 geom_hline error

Jim Nikelski jnikelski at gmail.com
Sun Oct 14 21:12:28 CEST 2007


Hi Hadley (and List),

   Your suggested geom_hline work-around did the trick.  Also, thanks
for the info regarding axis labels. My world is a happy place again.
Enjoy your weekend  ;)

-Jim

On 10/14/07, hadley wickham <h.wickham at gmail.com> wrote:
> On 10/14/07, Jim Nikelski <jnikelski at gmail.com> wrote:
> > Hello R-List
> >
> >     I've run  into a minor problem with ggplot2. In particular, I get
> > an error message when trying to plot a horizonal line through zero.
> > Here is what I do:
> >
> > plt.df <- subset(xfm.df, select=c(stage, subj, tX))
> > plt <- ggplot(pp.df, aes(x=stage, y=tX, group=subj)) + geom_line()
> > plt
> > plt <- plt + geom_hline(intercept=0)
> > plt
> >
> >   The first plot yields a most lovely graph. Addition of the
> > geom_hline yields ...
> >
> > "Error in eval(expr, envir, enclos) : object "subj" not found"
>
> Can you try the following?
>
> plt + geom_hline(aes(group=1), intercept = 0)
>
> If that works, I'll fix it in the development version.
>
> >   On an unrelated note, does anyone know how I might change the
> > default axis names in ggplot? I suspect it's aes-related, but not
> > quite sure.
>
> The axis label is a property of the scale, so you set it by overriding
> the default scale:
>
> plot + scale_y_continuous("New y axis label")
>
> Hadley
>
> --
> http://had.co.nz/
>



More information about the R-help mailing list