[R] plot points using circles filled half in red and half in blue.

Greg Snow 538280 at gmail.com
Wed Mar 28 22:59:44 CEST 2012


I would use the my.symbols function from the TeachingDemos package
(but then I might be a little bit biased), here is a simple example:

library(TeachingDemos)

x <- runif(25)
y <- runif(25)
z <- sample(1:4, 25, TRUE)

ms.halfcirc2 <- function(col, adj=pi/2, ...) {
	theta <- seq(0, 2*pi, length.out=300)+adj
	x <- cos(theta)
	y <- sin(theta)
	if(col==1) {
		polygon(x,y)
	} else if(col==2) {
		polygon(x,y, col='red')
	} else if(col==3) {
		polygon(x,y, col='blue')
	} else {
		polygon(x[1:150], y[1:150], border=NA, col='red')
		polygon(x[151:300], y[151:300], border=NA, col='blue')
		polygon(x,y)
	}
}

my.symbols( x, y, ms.halfcirc2, inches=1/5, add=FALSE,
	symb.plots=TRUE, col=z)


# spice it up a bit
my.symbols( x, y, ms.halfcirc2, inches=1/5, add=FALSE,
	symb.plots=TRUE, col=z, adj=runif(25, 0, pi))


Adjust things to fit better what you want.

On Tue, Mar 27, 2012 at 8:49 PM, alan <alan.wu2007 at gmail.com> wrote:
> I want to plot many points and want to use circles. The filling color
> depends on variable a. if a=1, then not fill
> if a=2 then fill with red, if a=3 then fill with blue, if a=4, fill
> half with red and half with blue. Can anyone tell me how to plot the
> case "a=4"? Thanks a lot
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com



More information about the R-help mailing list