How to make colored circles in R?

In R, I can plot circles at specified sizes using the symbols() function, but for some reason it won’t allow me to do it in color. For example, try this:

symbols (0, 0, circles=1, col="red")

It makes a black circle, just as if the “col” argument had never been specified. What’s wrong?

P.S. I could just write my own function to draw circles, but that would be cheating. . . .

13 thoughts on “How to make colored circles in R?

  1. Use "fg" (foreground) for the boundary of the symbol and, if you wish to fill it "bg" (background) for the fill colour. Don't ask me why.

  2. Thanks for the help, everyone!

    Bob: You seem to be channeling a well-known denizen of the R-help list with your comment. But, let me tell you, I did read the help page! It had the following:

    <pre>

    … graphics parameters can also be passed to this function

    </pre>

    And so I foolishly assumed I could just pass along whatever graphics parameters I wanted. When "col" didn't work, I had no idea what to do.

    Now that I've been told what to look for, I can see that "fg" and "bg" are parameters in the function, but I didn't notice them when I looked at the help function. One thing that certainly doesn't help is that the help page is full of unnecessary info: xlab, ylab, main, xlim, ylim are standard plotting options. I didn't notice the new stuff ("fg" and "bg") amid the clutter of the old.

    I also tried googling "R symbols color" and various other combinations but with no luck.

    Dirk: Yes, I must learn ggplot2. Perhaps that wouldn't be a bad New Year's resolution?

  3. Hi Andrew, as all the others I found it as well.

    I found it by just calling 'symbols' to look at the code. In this case it's nothing much impressive to look at. On the second line you see the author reassigning the par("col").

  4. This is probably the wrong place to ask, but it should be a snap for you guys.

    How do you add x-lim and y-lim to a hexbin scatterplot? It doesn't allow me to do that, or any par() functions either.

Comments are closed.