'R: How to add fill color to a dot with legend with black circle outline

I am trying to create a legend (with empty plot) where each dot is associated with a group, but can't seem to figure out how to add fill color while having a black outline. It seems that my bg parameter is not working.

This is what my code looks like:

plot(NULL ,xaxt='n',yaxt='n',bty='n',ylab='',xlab='', xlim=0:1, ylim=0:1)
legend("topleft", legend =c("X", "A1", "A2", "A3", "A4", "A5", "A6"),pch=21, pt.cex=1.5, cex=0.8, bty='n', y.intersp=1.1, bg = c("black", "red", "yellow", "green", "cyan", "blue", "magenta"), col = "black")

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source