[R] ggplot2 geom_hline error

hadley wickham h.wickham at gmail.com
Sun Oct 14 20:35:48 CEST 2007

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")



More information about the R-help mailing list