Ggplot: buggy fill and colour legends for shapes pch=21:25

38 Views Asked by At

I'm trying to make a scatterplot with dynamic variables for x, y, shape, shape fill, and shape colour (aka border/stroke), when using shape pch 21:25 (those shapes with fills and borders). Colour/fill work independently but reveal two bugs:

data(mtcars)
mtcars$makeModel <- rownames(mtcars)

shape - plot & legend as anticipated:

ggplot(data = mtcars) +
  geom_point(mapping = aes(x = mpg,
                           y = makeModel,
                           shape = factor(gear))) +
  scale_shape_manual(values = c(21:23))

1

colour - plot & legend as anticipated:

ggplot(data = mtcars) +
  geom_point(mapping = aes(x = mpg,
                           y = makeModel,
                           colour = factor(carb)))

2

fill - does nothing on standard pch - plot & legend both black:

ggplot(data = mtcars) +
  geom_point(mapping = aes(x = mpg,
                           y = makeModel,
                           fill = factor(carb)))

3

shape & fill - fills correctly on plot but legend colours all black. Bug candidate:

ggplot(data = mtcars) +
  geom_point(mapping = aes(x = mpg,
                           y = makeModel,
                           shape = factor(gear),
                           fill = factor(carb))) +
  scale_shape_manual(values = c(21:23))

4

shape & colour - colours correctly on plot, legend colours are correct but fills not borders. Bug candidate 2:

ggplot(data = mtcars) +
  geom_point(mapping = aes(x = mpg,
                           y = makeModel,
                           shape = factor(gear),
                           colour = factor(carb))) +
  scale_shape_manual(values = c(21:23))

5

shape & colour & fill - colours correctly on plot, legend colours are correct but fills not borders. Fills are correct on plot but legend colours all black. Both bugs together:

ggplot(data = mtcars) +
  geom_point(mapping = aes(x = mpg,
                           y = makeModel,
                           shape = factor(gear),
                           fill = factor(cyl),
                           colour = factor(carb))) +
  scale_shape_manual(values = c(21:23))

6

Similar to as raised here, thoguh I feel this is a bug, or at least a feature request, for ggplot.

0

There are 0 best solutions below