Can't remove legend

42 views
Skip to first unread message

Stuart Luppescu

unread,
Jun 11, 2013, 5:49:53 PM6/11/13
to ggplot2
Hello all, I'm trying to completely remove the legend in my plot but I'm
failing. I have this code:

ggplot(acno, aes(x=survey_year, y=item_displ, color=as.factor(item_id)))
+
geom_line() +
theme(legend.position="none")

The last line gives this message:
Error: ggplot2 doesn't know how to deal with data of class uneval

I have also tried:
scale_color_discrete(guide=FALSE)
and
guides(color=FALSE)
but they all give the same error. Anyone have a clue?

TIA.
--
Stuart Luppescu <s...@ccsr.uchicago.edu>
University of Chicago

Stuart Luppescu

unread,
Jun 11, 2013, 7:27:45 PM6/11/13
to ggp...@googlegroups.com
On 鐃緒申, 2013-06-11 at 16:49 -0500, Stuart Luppescu wrote:
> Hello all, I'm trying to completely remove the legend in my plot but I'm
> failing. I have this code:
>
> ggplot(acno, aes(x=survey_year, y=item_displ, color=as.factor(item_id)))
> +
> geom_line() +
> theme(legend.position="none")
>
> The last line gives this message:
> Error: ggplot2 doesn't know how to deal with data of class uneval
>
> I have also tried:
> scale_color_discrete(guide=FALSE)
> and
> guides(color=FALSE)
> but they all give the same error. Anyone have a clue?

Never mind. I was just being stupid. It was something unrelated.

--
Stuart Luppescu <s...@ccsr.uchicago.edu>

Ben Bond-Lamberty

unread,
Jun 11, 2013, 9:39:03 PM6/11/13
to Stuart Luppescu, ggplot2
The problem isn't with the " theme(legend.position='none')" line,
which is correct. Something else is going on. I would suggest first
building your base plot and assigning it to a variable, and verify
that it renders correctly. Then remove the legend. For example

p <- ggplot( ... )
print( p )
print( p + theme(legend.position="none") )

Ben
Reply all
Reply to author
Forward
0 new messages