Skip to content

Help with removing extra legend elements in ggplot

6 messages · scoyoc, David Winsemius, Dennis Murphy +1 more

#
On Nov 19, 2013, at 3:44 PM, Matthew Van Scoyoc wrote:

            
Try this workaround to what sounds like a bug:

library(grid)

# then repeat the call.
#
The additional element comes from this code:

geom_point(aes(color = VegType, shape = VegType, size = 10))

Take the size argument outside the aes() statement and the legend will
disappear:

geom_point(aes(color = VegType, shape = VegType), size = 10)

The aes() statement maps a variable to a plot aesthetic. In this case
you're mapping VegType to color and shape. You want to *set* the size
aesthetic to a constant value, and that is done by assigning the value
10 to the size aesthetic outside of aes().

Dennis
On Tue, Nov 19, 2013 at 4:35 PM, Matthew Van Scoyoc <scoyoc at gmail.com> wrote:
5 days later
#
On Tue, 19 Nov 2013 16:44:11 -0700
Matthew Van Scoyoc <scoyoc at gmail.com> wrote:
You want to consider this as a programming bug in your code.  Executing
each line sequentially shows that the problem appears in the second
line:

nmds.fig + geom_point(aes(color = VegType, shape = VegType, size = 10))

?aes() and ?geom_point() reveals a misplaced right parenthesis. "Size"
belongs to geom_point(), not aes() as you have it grouped.

jwdougherty