Yes, you need to use fill
for the inside color and color
for the line color. And you need to use shapes that differentiate between the two (that is, shapes 21-25. Search "r pch" or see the help page at ?pch
for all the shapes). Unfortunately, for the legends to look right, we need to manually specify shapes for the legends. You may also want to use at least one manual
scale (e.g., scale_fill_manual
) specifying your own colors so that the fill and line colors are more different.
ggplot(mtcars,
aes(
x = wt,
y = mpg,
color = factor(carb),
fill = factor(cyl),
shape = factor(vs)
)) + geom_point(size = 2, stroke = 1.5) +
scale_shape_manual(values = c(21, 24)) +
scale_fill_hue(guide = guide_legend(override.aes = list(shape = 21))) +
scale_color_hue(guide = guide_legend(override.aes = list(shape = 21)))
See also the example at the bottom of the ?geom_point
help page:
# For shapes that have a border (like 21), you can colour the inside and
# outside separately. Use the stroke aesthetic to modify the width of the
# border
ggplot(mtcars, aes(wt, mpg)) +
geom_point(shape = 21, colour = "black", fill = "white", size = 5, stroke = 5)
scale_shape_manual(values = c(21, 22, 23) )
or something and then usefill
forcarb
. – aosmith