Here's a silly data.frame
:
df <- read.table(textConnection(
"pole medal bag x y
north gold paper 0.852 0.423
north gold plastic 0.277 0.055
north silver paper 0.257 0.211
north silver plastic 0.457 0.614
north bronze paper 0.825 0.299
north bronze plastic 0.672 0.126
south gold paper 0.482 0.764
south gold plastic 0.603 0.869
south silver paper 0.327 0.451
south silver plastic 0.147 0.672
south bronze paper 0.140 0.466
south bronze plastic 0.833 0.325
"), header = TRUE)
I know how to plot a scatterplot for these data in a way that uses color and shape to indicate two of the factor attributes; for example:
library(ggplot2)
ggplot(data = df, aes(x = x, y = y)) +
geom_point(size = 4, aes(shape = pole, color = bag))
I would like to add one more point feature to indicate a third factor attribute (in this case medal
). The one possibility that comes to mind is a colored outline.
Is there a convenient way to do this? (One tricky aspect of the problem is that the color palette for the outlines must be distinct from that used for the point fills, because, for each point, the outline and the fill must be visually distinguishable.)
UPDATE:
When I try Gregor's suggestion, the points look right, but the legend is messed up: