Thanks for posting your question, this turned out to be a fun challenge! A couple of high level points. First, plotting symbols 21 through 25 allow you to set the interior color with the fill
aesthetic and the border with the color
aesthetic. I mapped the carb
variable to the fill
aesthetic. Sadly, although you can change the thickness of the border with the stroke
aesthetic, there is no scale_stroke_manual
function. I had hoped to map gear
to stroke
and set it equal to zero for 5 cylinder cars. Instead, my strategy was to map the number of gears to the color
aesthetic. Then using scale_color_manual
, I used the alpha
argument of rgb
to make the border of the squares transparent. Because that made the squares appear a bit smaller, I bumped up their size a smidge. Finally, you'll notice that I modified the appearance of the legends to make it clear that a circle in the shape legend wasn't the same as a circle in the fill legend.
I hope this is what you were after. Holler if you have any questions!
library(tidyverse)
ggplot(mtcars, aes(x=mpg, y=cyl,
fill=as.character(carb),
shape=as.character(gear),
size=as.character(gear),
color=as.character(gear))) +
geom_point() +
scale_shape_manual(breaks=c(3, 4, 5),
values=c(21, 24, 22),
guide=guide_legend(override.aes = list(fill="black",
color="black"))) +
scale_color_manual(breaks=c(3, 4, 5),
values=c("black", "black", rgb(0, 0, 0, alpha=0))) +
scale_size_manual(breaks=c(3, 4, 5),
values=c(3, 3, 4)) +
scale_fill_manual(breaks=c(1, 2, 3, 4, 6, 8),
values=rainbow(6),
guide=guide_legend(override.aes = list(color=rainbow(6),
shape=18,
size=5)))