[R] shade overlapping portions of circles (or other shapes)

Paul Johnson pauljohn32 at gmail.com
Wed Aug 15 18:43:07 CEST 2012


I'm making some illustrations and it would be convenient to
automatically shade the overlapping portions of circles.  These
illustrations are for Social Choice theory, a field in political
science and economics.  I've wrestled together some examples so you
can see what I mean, but have not mastered the "color overlapping
sections" problem (as you will see):

http://pj.freefaculty.org/scraps/t-m15g.pdf

The shaded area does not overlap perfectly, mainly because I isolated
the points manually with locator(). Tedious!

I've not found R functions just for this.  Are there any packages?

You can get an idea of the problem if you run, for example

library(plotrix)
example(draw.circle)

See the red and the blue circles overlap?  What's the best way to
"shade in" that overlapping area.

I don't have Mathematica anymore, but they seem to be able to do this
more-or-less easily

http://mathematica.stackexchange.com/questions/2554/how-to-plot-venn-diagrams-with-mathematica

I want to make R do same ( or develop package to do it).

I was under some pressure to get a graph finished that I linked to
above. But I would not want to do it that way again. The shapes won't
always  be perfect circles, they may be ellipses or other convex
shapes.  But if I could understand the problem for circles, maybe I
could solve for others.

Do you have suggestions?

I am considering this. Collect the co-ordiates from the circle points

 C1 <- draw.circle(3.5,7,0.8,border="blue",lty=2,lwd=2)
 C2 <- draw.circle(2.5,8,0.6,border="red",lty=3,lwd=3)

Can I isolate the relevant arcs from C1 and C2? If I could, I'd join them

Cjoin <- list(x = c(C1$x, C2$x), y = c(C1$y, C2$y))

And use that for plotting.

pj


-- Paul E. Johnson
Professor, Political Science    Assoc. Director
1541 Lilac Lane, Room 504     Center for Research Methods
University of Kansas               University of Kansas
http://pj.freefaculty.org            http://quant.ku.edu



More information about the R-help mailing list